Psycopg2 module not found Python2.7
I have installed psycopg2 via pip, but my programs cannot find it. So, I tried to install psycopg2 again via pip:
user@ubuntu:~/Desktop/progFolder$ sudo pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/local/lib/python2.7/dist-packages
Cleaning up...
Then I tried to use a program that imports it:
user@ubuntu:~/Desktop/progFolder$ python myProg.py
Traceback (most recent call last):
File "myProg.py", line 6, in <module>
import psycopg2
ImportError: No module named psycopg2
And I tried to just import directly into python:
user@ubuntu:~/Desktop/progFolder$ python
Python 2.7.5 (default, Nov 9 2014, 14:14:12)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
So, I typed my python path.
>>> import sys
>>> print sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
And noticed that the path contains the path to psycopg2.
psycopg2 in /usr/local/lib/python2.7/dist-packages
So, I have no idea why this is happening. Any help would be appreciated.
UPDATE: I did
>>>help()
>>>modules
And psycopg2 was not included in the list of other modules. (it doesn't help me, but it might help you)
source to share
Your pip looks fine (i.e. system / default). However, your Python executable is something that hasn't appeared by default since 14.04 LTS (for example, on my 14.04 system, this is /usr/bin/python
). Have you installed this Python yourself? Then you need to install (and use) the appropriate one pip
. (Python usually came with pip installed, but apparently it doesn't in this case.)
pip can be installed quite simply from the installation instructions .
Although first make sure that
-
you installed it yourself
/usr/local/bin/python
. That is, it didn't come with some other software that you installed and that, along the way, decided to install Python there. -
you want to use
/usr/local/bin/python
(I assume this is a newer version of Python 2.7, default 14.04 LTS, apparently 2.6.7 as of 2015-08-03).
source to share