但仍然收到importerror

但仍然收到importerror

本文介绍了我在虚拟环境中安装了psycopg2,但仍然收到importerror psycopg2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循以下步骤:[我正在使用Windows 8,Python 2.7.6]

I followed the following steps: [I am using Windows 8, Python 2.7.6]


  1. 我创建了一个虚拟环境venv,然后将pip安装在requirements.txt上以安装所有库。

  2. 我必须显式创建一个名为config.py的文件来设置os.environ变量。然后,我正在其他文件中执行导入配置。

  3. 我已经安装了postgresql并将bin文件夹添加到环境路径中

  4. psycopg2无法从安装运行requirements.txt。因此,我从网上下载了带有setup.py的zip文件,并在虚拟环境中运行了setup.py。稍后当我在虚拟环境中执行 pip install psycopg2时,它表示已满足要求。

  5. 现在我运行venv / Scripts / .py并收到以下错误:

  1. I created a virtual environment venv and then did pip install on requirements.txt to install all the libraries.
  2. I had to explicitly create a file called config.py to set the os.environ variables. Then, I am doing import config in other files.
  3. I have installed postgresql and added bin folder to environment path
  4. psycopg2 was failing to install from running requirements.txt. So, I downloaded the zip with setup.py from online, and ran the setup.py in the virtial environment. Later when I did "pip install psycopg2" in the virtual env, it said requirement already satisfied.
  5. Now I ran venv/Scripts/.py and got the following error:



Traceback (most recent call last):
  File "remote-alert.py", line 5, in <module>
    from database import db_session
  File "d:\Documents\Tutorials\Technologies\inMobi\soynerdito\HobbesAlert\databa
se.py", line 12, in <module>
    isolation_level="READ UNCOMMITTED" )
  File "d:\Documents\Tutorials\Technologies\inMobi\soynerdito\HobbesAlert\venv\l
ib\site-packages\sqlalchemy\engine\__init__.py", line 344, in create_engine
    return strategy.create(*args, **kwargs)
  File "d:\Documents\Tutorials\Technologies\inMobi\soynerdito\HobbesAlert\venv\l
ib\site-packages\sqlalchemy\engine\strategies.py", line 73, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "d:\Documents\Tutorials\Technologies\inMobi\soynerdito\HobbesAlert\venv\l
ib\site-packages\sqlalchemy\dialects\postgresql\psycopg2.py", line 401, in dbapi

import psycopg2
ImportError: No module named psycopg2


在错误输出中,给定文件psycopg2.py正在被访问路径。那么为什么我会收到错误消息?

In the error output, the file psycopg2.py, which is being accessed exists in the given path. Then why I am getting the error?

我检查了许多在线给出的解决方案,例如postgresql必须在PATH中的bin文件夹中安装。我应该只使用虚拟env python.exe来运行我的程序,而不应该以超级用户身份运行它,等等。到目前为止,对我来说什么都没有用。

I checked many solutions given online, like postgresql must be installed with bin folder in PATH. I should use only virtual env python.exe to run my program, I should not run it as a superuser, etc. Nothing worked for me till now.

请帮助!

推荐答案

不幸的是,psycopg2需要在每种体系结构上进行编译。而且我敢肯定,如果您检查了 pip install psycopg2 的输出,您会注意到一些错误(即使最终最终会安装它)。

Unfortunately, psycopg2 needs to compile on each architecture; and I am sure if you checked the output of pip install psycopg2 you would have noticed some errors (even though, in the end, it will end up installing it).

最好安装预编译的Windows二进制文件,您可以在其中找到。

It is best to install the pre-compiled windows binary, which you can find at this website.

这篇关于我在虚拟环境中安装了psycopg2,但仍然收到importerror psycopg2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:28