在虚拟环境中安装psycopg2(Ubuntu 10.04,Python 2.5)
我在虚拟环境中安装psycopg2时遇到了问题。
我尝试了那里的不同方法:http://www.saltycrane.com/blog/2009/07/using-psycopg2-virtualenv-ubuntu-jaunty/
我最后尝试的步骤是...
我用 -p python2.5 --no-site-packages
创建了一个虚拟环境。
然后我安装了libpq-dev: apt-get install libpq-dev
在虚拟环境中,我执行了这个命令: easy_install -i http://downloads.egenix.com/python/index/ucs4/ egenix-mx-base
然后当我尝试 pip install psycopg2==2.0.7
时,出现了这个错误:
Installing collected packages: psycopg2
Running setup.py install for psycopg2
building 'psycopg2._psycopg' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.2.2 (dt dec ext pq3)" -DPG_VERSION_HEX=0x080404 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -DHAVE_PQPROTOCOL3=1 -I/usr/include/python2.5 -I. -I/usr/include/postgresql -I/usr/include/postgresql/8.4/server -c psycopg/psycopgmodule.c -o build/temp.linux-i686-2.5/psycopg/psycopgmodule.o -Wdeclaration-after-statement
psycopg/psycopgmodule.c:27:20: error: Python.h: No such file or directory
In file included from psycopg/psycopgmodule.c:31:
./psycopg/python.h:31:26: error: structmember.h: No such file or directory
./psycopg/python.h:34:4: error: #error "psycopg requires Python >= 2.4"
In file included from psycopg/psycopgmodule.c:32:
有没有人知道怎么解决这个问题吗?
谢谢。
1 个回答
来自 python-list:
Diez: 安装 python-dev 包。这个包里有一个叫 Python.h 的文件,正是上面错误信息提到的。通常,搜索 debian/ubuntu 包的描述,看看缺少哪些头文件,能帮助你知道该安装什么。
Pascal: 我已经安装了;至少对于 Python 2.6 来说是这样,不确定 Python 2.5 是否也正确。python2.5-dev 这个包不可用,但 python-old-doctools 似乎可以替代它。
Diez: 这对于 python2.5 来说 100% 是不正确的。正如错误信息所示——它缺失了。如果在某个地方找不到这个包,你应该考虑自己编译 Python,如果你必须使用 2.5 的话。
Alex: Ubuntu 10.04 没有完整的 Python 2.5 包,这从缺少 python2.5-dev 就能看出来。你需要使用 Python 2.6,或者如果你真的必须使用 Python 2.5,就从源代码编译,试试 Debian 包,或者换个发行版。python-old-doctools 并不能替代 python-dev,看起来是为了让一些 latex 工具继续工作而临时处理的。
Pascal: 我最后创建了一个使用 Python 2.6 的虚拟环境,一切都很顺利(使用的是最新版本的 psycopg2)。