简体   繁体   中英

No module named psycopg2 even after i installed psycopg2

I have

#!/usr/bin/python3
import psycopg2

in my first couple lines of the code. However, it shows that

ImportError: No module named psycopg2

even after I install psycopg2

Below is the detail errors from the ternimal.

 432p1:/vagrant> pip3 install psycopg2
Collecting psycopg2
  Downloading psycopg2-2.7.3.1-cp35-cp35m-manylinux1_x86_64.whl (2.6MB)
    100% |████████████████████████████████| 2.6MB 526kB/s 
Installing collected packages: psycopg2
Successfully installed psycopg2-2.6.1
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
432p1:/vagrant> ./test-example.py pys.py
Traceback (most recent call last):
  File "./test-example.py", line 2, in <module>
    import psycopg2
ImportError: No module named psycopg2
432p1:/vagrant> ./clean-example.py
Traceback (most recent call last):
  File "./clean-example.py", line 2, in <module>
    import psycopg2
ImportError: No module named psycopg2
432p1:/vagrant> 

In addition i tried to run import in my python console and there is no error, however,when i run the test it has error

432p1:/vagrant> python3
Python 3.5.2 (default, Aug 18 2017, 17:48:00) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> ./test-example.py pys.py 
  File "<stdin>", line 1
    ./test-example.py pys.py 
    ^
SyntaxError: invalid syntax
>>> 

Thanks

Check if it was actually installed where you expected it to be -- you can compare other packages that have been imported successfully. Run pip show psycopg2 vs pip show pandas or some other package and compare if they're in the right place.

In my case, only the psycopg2 dist files had been installed in that directory for some reason, and so I uninstalled and reinstalled and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM