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管理”。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,但似乎找不到使用homebrew下载psycopg2的方法。我已经尝试过easy_install, pip安装和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?
如何解决这个问题?
117
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
然后进入你的虚拟环境中使用
pip install psycopg2
These two commands should solve the problem.
这两个命令应该可以解决这个问题。
5
first install apt-get install python-setuptools
首先安装apt-get install python-setuptools
then try easy_install psycopg2
然后试着easy_install psycopg2
4
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安装程序中安装的,这对我有帮助。我在尝试了“apt-get install”和“pip安装”之后做了这个:
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
4
I installed it successfully using these commands:
我使用以下命令成功安装:
sudo apt-get install libpq-dev python-dev
pip install psycopg2
2
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
1
It seems that you need gcc-4.0
, and it would be helpful to specify your OS type and version.
您似乎需要gcc-4.0,指定您的OS类型和版本会很有帮助。
Maybe this question will help you a bit: Installing GCC to Mac OS X Leopard without installing Xcode
也许这个问题会对您有所帮助:在Mac OS X Leopard中安装GCC而不安装Xcode
Update
更新
I'm a Windows user, so I can't test your setup, but a quick google pointed to some more links:
我是一个Windows用户,所以我不能测试你的设置,但是一个简单的谷歌指向更多的链接:
1
I encountered the No module named psycopg2.extensions
error when trying to run pip2 install psycopg2
on a Mac running Mavericks (10.9). I don't think my stack trace included a message about gcc, and it also included a hint:
我遇到了名为psycopg2的No模块。试图在运行Mavericks的Mac上运行pip2安装psycopg2时发生扩展错误(10.9)。我不认为我的堆栈跟踪包含关于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_config
file 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.
我在我的Postgres安装中查找了pg_config文件,并将包含该文件的文件夹添加到我的路径:/Applications/ postgre .app/ content / version /9.4/bin中。你的路径可能是不同的,特别是如果你安装了不同版本的Postgres——我只是在你找到bin/文件夹之前闲逛。在这样做之后,安装工作了。
1
try this:
sudo pip install -i https://testpypi.python.org/pypi psycopg2==2.7b2
.. this is especially helpful if you're running into egg error
试试这个:sudo pip安装- https://testpypi.python.org/pypicopg2 =2.7b2。如果您遇到鸡蛋错误,这将非常有用
on aws ec2 instances if you run into gcc error; try this
1. sudo yum install gcc python-setuptools python-devel postgresql-devel
2. sudo su -
3. sudo pip install psycopg2
在aws ec2实例上,如果您遇到gcc错误;试试这个1。sudo yum安装了gcc -setuptools python-devel postgresql-devel 2。sudo su - 3。sudo pip安装psycopg2
1
For Django 2
and python 3
install psycopg2
using pip3
:
对于Django 2和python 3,使用pip3安装psycopg2:
pip3 install psycopg2
1
pip install psycopg2-binary
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安装psycopg2-binary”。详情参见:http://initd.org/psycopg/docs/install.html # binary-install-from-pypi。
0
I used the extension after only importing psycopg2:
我在只导入psycopg2后使用了扩展:
import psycopg2
...
psycopg2.extensions.AsIs(anap[i])
0
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_install
or with pip
您可以从https://github.com/kennethreitz/osx-gcc-installer为macos安装gcc,在安装gcc之后,您将能够使用easy_install或pip安装psycopg
0
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.
这两个命令应该可以解决这个问题。