我有
#!/usr/bin/python3
import psycopg2
在我的前几行代码中。 但是,它显示了
ImportError: No module named psycopg2
即使我安装了psycopg2
以下是来自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>
此外我试图在我的python控制台中运行导入并且没有错误,但是,当我运行测试时它有错误
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
>>>
由于
答案 0 :(得分:0)
检查它是否实际安装在您期望的位置上-您可以比较已成功导入的其他软件包。运行pip show psycopg2
与pip show pandas
或其他软件包,并比较它们是否在正确的位置。
就我而言,由于某种原因,仅psycopg2 dist文件安装在该目录中,因此我卸载并重新安装后就可以使用了。