Python 错误:没有名为 psycopg2.extensions 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12728004/
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
Error: No module named psycopg2.extensions
提问by Jess
I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python manage.py runserver' in Terminal to get my localhost up but when I run the command, I see this response...
我正在尝试为我的 django 项目设置一个 PostgreSQL 数据库,我相信我现在已经完成了,这要归功于我对上一个问题的答复为 django 项目设置 postgreSQL 数据库的问题。我现在正在尝试在终端中运行命令“python manage.py runserver”来启动我的本地主机,但是当我运行该命令时,我看到了这个响应......
Error: No module named psycopg2.extensions
I'm not sure what this means - I have tried to download psycopg2 but can't seem to find a way to download psycopg2 using homebrew. I have tried easy_install, pip install and sudo but all return errors like this...
我不确定这意味着什么 - 我尝试下载 psycopg2,但似乎无法找到使用自制软件下载 psycopg2 的方法。我尝试过easy_install,pip install和sudo,但都返回这样的错误......
Downloading http://www.psycopg.org/psycopg/tarballs/PSYCOPG-2-4/psycopg2-2.4.5.tar.gz
Processing psycopg2-2.4.5.tar.gz
Writing /tmp/easy_install-l7Qi62/psycopg2-2.4.5/setup.cfg
Running psycopg2-2.4.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-l7Qi62/psycopg2-2.4.5/egg-dist-tmp-PBP5Ds
no previously-included directories found matching 'doc/src/_build'
unable to execute gcc-4.0: No such file or directory
error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1
How to fix this?
如何解决这个问题?
回答by f p
I used the extension after only importing psycopg2:
我只在导入 psycopg2 后使用了扩展:
import psycopg2
...
psycopg2.extensions.AsIs(anap[i])
回答by alexandrul
It seems that you need gcc-4.0, and it would be helpful to specify your OS type and version.
似乎您需要gcc-4.0,并且指定您的操作系统类型和版本会很有帮助。
Maybe this question will help you a bit: Installing GCC to Mac OS X Leopard without installing Xcode
也许这个问题会对你有所帮助:在不安装 Xcode 的情况下将 GCC 安装到 Mac OS X Leopard
Update
更新
I'm a Windows user, so I can't test your setup, but a quick google pointed to some more links:
我是 Windows 用户,所以我无法测试你的设置,但是一个快速的谷歌指向了更多的链接:
回答by Ponimas
you can install gcc for macos from https://github.com/kennethreitz/osx-gcc-installer
after instalation of gcc you'll be able to install psycopg with easy_installor with pip
您可以在安装 gcc
后从https://github.com/kennethreitz/osx-gcc-installer为 macos
安装 gcc,您将能够使用easy_install或使用psycopgpip
回答by user1667633
first install apt-get install python-setuptools
首先安装 apt-get install python-setuptools
then try easy_install psycopg2
然后尝试 easy_install psycopg2
回答by Fernando Munoz
The first thing to do is to install the dependencies.
首先要做的是安装依赖项。
sudo apt-get build-dep python-psycopg2
After that go inside your virtualenv and use
之后进入你的 virtualenv 并使用
pip install psycopg2-binary
These two commands should solve the problem.
这两个命令应该可以解决问题。
回答by Jayakumar Bellie
Check if you have installed psycopg2 if not
如果没有,请检查您是否安装了 psycopg2
sudo apt-get install psycopg2
Install the dependencies.
安装依赖项。
sudo apt-get build-dep python-psycopg2
These two commands should solve the problem.
这两个命令应该可以解决问题。
回答by arunas_t
This is what helped me on Ubuntu if your python installed from Ubuntu installer. I did this after unsuccessfully trying 'apt-get install' and 'pip install':
如果您的 python 是从 Ubuntu 安装程序安装的,这对我在 Ubuntu 上有帮助。我在尝试 'apt-get install' 和 'pip install' 失败后做了这个:
In terminal:
在终端:
sudo synaptic
then in synaptic searchfield write
然后在突触搜索字段中写入
psycopg2
choose
选择
python-psycopg2
mark it for installation using mouse right-click and push 'apply'. Of course, if you don't have installed synaptic, then first do:
使用鼠标右键单击并按“应用”将其标记为安装。当然,如果你还没有安装synaptic,那么首先要做:
sudo apt-get install synaptic
回答by hassan ketabi
I installed it successfully using these commands:
我使用以下命令成功安装了它:
sudo apt-get install libpq-dev python-dev
pip install psycopg2
回答by JJSanDiego
In python 3.4, while in a virtual environment, make sure you have the build dependencies first:
在 python 3.4 中,在虚拟环境中,首先确保您有构建依赖项:
sudo apt-get build-dep python3-psycopg2
Then install it:
然后安装它:
pip install psycopg2
回答by Galen Long
I encountered the No module named psycopg2.extensionserror when trying to run pip2 install psycopg2on a Mac running Mavericks (10.9). I don't think my stack trace included a message about gcc, and it also included a hint:
No module named psycopg2.extensions尝试pip2 install psycopg2在运行 Mavericks (10.9) 的 Mac 上运行时遇到错误。我不认为我的堆栈跟踪包含有关 gcc 的消息,它还包含一个提示:
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
I looked for the pg_configfile in my Postgres install and added the folder containing it to my path: /Applications/Postgres.app/Contents/Versions/9.4/bin. Your path may be different, especially if you have a different version of Postgres installed - I would just poke around until you find the bin/folder. After doing this, the installation worked.
我pg_config在 Postgres 安装中查找该文件,并将包含它的文件夹添加到我的路径中:/Applications/Postgres.app/Contents/Versions/9.4/bin. 您的路径可能会有所不同,尤其是如果您安装了不同版本的 Postgres - 我只会四处看看,直到您找到该bin/文件夹。这样做后,安装工作。

