Python 导入错误:没有名为 psycopg2 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12906351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named psycopg2
提问by ws_123
When installing process of OpenERP 6, I want to generate a config file with this command,
在安装 OpenERP 6 的过程中,我想用这个命令生成一个配置文件,
cd /home/openerp/openerp-server/bin/
cd /home/openerp/openerp-server/bin/
./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg
./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg
But it was always showed a message
但它总是显示一条消息
ImportError: No module named psycopg2
ImportError: No module named psycopg2
When I check for psycopg2 package, it's already installed,
当我检查 psycopg2 包时,它已经安装了,
Package python-psycopg2-2.4.5-1.rhel5.x86_64already installed and latest version
python-psycopg2-2.4.5-1.rhel5.x86_64已安装的软件包和最新版本
Nothing to do
没事做
What's wrong with this?
这有什么问题?
My server is CentOS, I've installed python 2.6.7.
我的服务器是 CentOS,我已经安装了 python 2.6.7。
回答by Nilesh
Please try to run the command import psycopg2on the python console. If you get the error then check the sys.pathwhere the python look for the install module. If the parent directory of the python-psycopg2-2.4.5-1.rhel5.x86_64is there in the sys.pathor not. If its not in the sys.paththen run export PYTHONPATH=<parent directory of python-psycopg2-2.4.5-1.rhel5.x86_64>before running the openerp server.
请尝试import psycopg2在 python 控制台上运行该命令。如果出现错误,请检查sys.pathpython 查找安装模块的位置。的父目录是否在python-psycopg2-2.4.5-1.rhel5.x86_64那里sys.path。如果它不在sys.path然后运行export PYTHONPATH=<parent directory of python-psycopg2-2.4.5-1.rhel5.x86_64>openerp 服务器之前运行。
回答by scarver2
You need to install the psycopg2module.
您需要安装该psycopg2模块。
On CentOS: Make sure Python 2.7+ is installed. If not, follow these instructions: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
在 CentOS 上:确保安装了 Python 2.7+。如果没有,请按照以下说明操作:http: //toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
# Python 2.7.6:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
$ tar xf Python-2.7.6.tar.xz
$ cd Python-2.7.6
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall
$ yum install postgresql-libs
# First get the setup script for Setuptools:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# Then install it for Python 2.7 and/or Python 3.3:
$ python2.7 ez_setup.py
$ easy_install-2.7 psycopg2
Even though this is a CentOS question, here are the instructions for Ubuntu:
尽管这是一个 CentOS 问题,但这里是 Ubuntu 的说明:
$ sudo apt-get install python3-pip python-distribute python-dev
$ easy_install psycopg2
回答by Tarique
Step 1: Install the dependencies
第一步:安装依赖
sudo apt-get install build-dep python-psycopg2
Step 2: Run this command in your virtualenv
第 2 步:在您的 virtualenv 中运行此命令
pip install psycopg2
Ref: Fernando Munoz
参考:费尔南多·穆尼奥斯
回答by Cp Verma
Try with these:
试试这些:
virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2
run python and try to import if you insist on installing it on your systems python try:
运行 python 并尝试导入,如果你坚持在你的系统上安装它 python 尝试:
pip3 install psycopg2
回答by Walter Schweitzer
For Python3
对于 Python3
Step 1: Install Dependencies
第 1 步:安装依赖项
sudo apt-get install python3 python-dev python3-dev
Step 2: Install
第 2 步:安装
pip install psycopg2
回答by Aquarius
Recently faced this issue on my production server. I had installed pyscopg2 using
最近在我的生产服务器上遇到了这个问题。我已经安装了 pyscopg2 使用
sudo pip install psycopg2
It worked beautifully on my local, but had me for a run on my ec2 server.
它在我的本地运行良好,但让我在我的 ec2 服务器上运行。
sudo python -m pip install psycopg2
The above command worked for me there. Posting here just in case it would help someone in future.
上面的命令在那里对我有用。在这里发布以防万一它会在未来帮助某人。
回答by Yan QiDong
Use psycopg2-binaryinstead of psycopg2.
使用psycopg2-binary而不是psycopg2。
pip install psycopg2-binary
Or you will get the warning below:
或者您将收到以下警告:
UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
用户警告:psycopg2 轮包将从 2.8 版开始重命名;为了继续从二进制安装,请改用“pip install psycopg2-binary”。有关详细信息,请参阅:http: //initd.org/psycopg/docs/install.html#binary-install-from-pypi。
Reference: Psycopg 2.7.4 released | Psycopg
回答by Safvan CK
I faced the same issue and resolved it with following commands:
我遇到了同样的问题并使用以下命令解决了它:
sudo apt-get install libpq-dev
pip install psycopg2
回答by Soft Technoes
check correctly if you had ON your virtual env of your peoject, if it's OFF then make it ON. execute following cammands:
正确检查您是否打开了您的 peoject 的虚拟环境,如果它已关闭,则将其打开。执行以下命令:
workon <your_env_name>
python manage.py runserver
It's working for me
它对我有用
回答by Y. Yazarel
Try installing
尝试安装
psycopg2-binary
psycopg2-二进制
with
pip install psycopg2-binary --user
和
pip install psycopg2-binary --user

