简体   繁体   English

ImportRrror:没有名为“ psycopg2”的模块

[英]ImportRrror: no module named 'psycopg2'

I'm attempting to use PostgreSQL as my data base and I'm running into an issue when I try to start my server. 我正在尝试使用PostgreSQL作为数据库,并且在尝试启动服务器时遇到问题。 Here's what I'm doing: 这是我在做什么:

  • I have a virtual environment set up and activated 我已经设置并激活了虚拟环境
  • Django 1.8.4 is installed Django 1.8.4已安装
  • psycopg2 2.5.2 is installed 安装了psycopg2 2.5.2
  • wheel 0.24.0 is installed 车轮0.24.0已安装

I'm using python 3.4. 我正在使用python 3.4。

Adding pip freeze output as requested: 根据要求添加点冻结输出:

Django==1.8.4
psycopg2==2.5.2
wheel==0.24.0

when I run the server using the default sqlite3 db I have no issue; 当我使用默认的sqlite3 db运行服务器时,我没有问题; it runs fine. 运行正常。 As soon as I switch over to postgres I get the following error: ImportError: no module named psycopg2. 切换到postgres后,我将收到以下错误:ImportError:没有名为psycopg2的模块。

pip install psycopg2 wasn't working so I installed psycopg2 from github using this command: pip install git+https://github.com/nwcell/psycopg2-windows.git@win64-py34#egg=psycopg2 pip install psycopg2无法正常工作,因此我使用以下命令从github安装了psycopg2: pip install git+https://github.com/nwcell/psycopg2-windows.git@win64-py34#egg=psycopg2

Guidance is greatly appreciated. 指导深表感谢。

Seems like you are in Windows. 好像您在Windows中。 For windows, you need to download and install from the binary files. 对于Windows,您需要从二进制文件下载并安装。 You can download the installers from here. 您可以从此处下载安装程序。

http://www.stickpeople.com/projects/python/win-psycopg/ http://www.stickpeople.com/projects/python/win-psycopg/

Make sure you select the correct file based on architecture and python version. 确保根据架构和python版本选择正确的文件。

After installing the psycopg2 with the installers, re-create your virtual environments to have the plugin working. 使用安装程序安装psycopg2之后,重新创建您的虚拟环境以使插件正常工作。

Alternatively you can download and install C++ re-distributables from msdn download centre and then try with pip install psycopg2 或者,您可以从msdn下载中心下载并安装C ++可再发行内容,然后尝试使用pip install psycopg2

It is important to specify operating system you are on, as I guess from comment you are using windows. 重要的是要指定您所使用的操作系统,因为从评论中我猜您正在使用Windows。

On windows if you do not wont to install Visual C++ libraries you can just download whl file of the package. 在Windows上,如果您不安装Visual C ++库,则只需下载软件包的whl文件即可。

http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg

choose correct architecture and python version for you and run 为您选择正确的架构和python版本并运行

pip install path/to/packagename.whl

make sure you are using pip version 6 or newer 确保您使用的是pip版本6或更高版本

在安装psycopg2之前,请isntall sudo apt-get build-dep python-psycopg2

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

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