简体   繁体   English

在windows上的virtualenv中安装psycopg2(postgresql)

[英]Installing psycopg2 (postgresql) in virtualenv on windows

I installed psycopg2 in virtualenv using easy_install psycopg2 . 我使用easy_install psycopg2在virtualenv中安装了easy_install psycopg2 I did not see any errors and looks like installation went fine.. there is an egg file created in the site-packages dir for psycopg2.. 我没有看到任何错误,看起来安装很顺利..有一个鸡蛋文件在site-packages目录中为psycopg2创建..

but when I run import psycopg2 in the interpreter, I am getting following error.. any clue? 但是当我在解释器中运行导入psycopg2时,我得到以下错误..任何线索? How can I fix it.. any other way to install psycopg2 in virtualenv.. 我该如何解决..在virtualenv中安装psycopg2的任何其他方法..

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\psycopg2\__init__.py", line 69, in <module>
  File "build\bdist.win32\egg\psycopg2\_psycopg.py", line 7, in <module>
  File "build\bdist.win32\egg\psycopg2\_psycopg.py", line 6, in __bootstrap__

Thanks. 谢谢。

Edit: this solution is outdated. 编辑:此解决方案已过时。 Refer to this answer instead. 请参阅此答案

I had the same problem. 我有同样的问题。 Following the suggestion on the download page of the Windows port for getting it working on Zope worked for me under virtualenv (also in the non-virtual install): 按照Windows端口的下载页面上的建议,让它在Zope上工作,在virtualenv(也在非虚拟安装中)下工作:

  1. Download the executable, rename the .exe extension to .zip 下载可执行文件,将.exe扩展名重命名为.zip
  2. Extract the file contents. 提取文件内容。
  3. Copy the psycopg2 folder to MyEnv/Lib 将psycopg2文件夹复制到MyEnv / Lib
  4. Copy the egg to MyEnv/Lib/site-packages 将鸡蛋复制到MyEnv / Lib / site-packages

Have you checked that PostgreSQL's 'bin' directory is on the system path? 你检查过PostgreSQL的'bin'目录是否在系统路径上? Check with a quick typing of 'set' and see what you get. 快速输入'set'进行检查,看看你得到了什么。

This is the most common cause of import failures of psycopg2 on Windows. 这是Windows上psycopg2导入失败的最常见原因。

There is an alternative to install python packages in your computer ie, pip . 有一种替代方法可以在您的计算机中安装python包,即pip You can download python packages by just executing:- 您可以通过执行以下命令下载python包: -

    pip install psycopg2 

The general format of the command is 命令的一般格式是

    pip install [package-name]

PS:- To install python packages globally through pip PS: - 通过pip全局安装python包

    sudo pip install [package-name]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM