简体   繁体   English

Virtualenv没有名为zlib的模块

[英]Virtualenv no module named zlib

I'm trying to create Python 2.7 virtual env under Python2.6, I'm simply running: 我正在尝试在Python2.6下创建Python 2.7虚拟环境,我只是运行:

virtualenv --python=python27 #python27 correctly leads to my python installation in /opt/python2.7/bin/python

Virtualenv fails with following error Virtualenv失败并出现以下错误

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/virtualenv.py", line 17, in <module>
import zlib
ImportError: No module named zlib

This puzzles me because: 这让我很困惑,因为:

1) I clearly do have python zlib module. 1)我显然有python zlib模块。 I can import it easily when I run "import zlib" in interactive environment of python 2.6. 当我在python 2.6的交互式环境中运行“import zlib”时,我可以轻松导入它。

2) I also have zlib installed in my system (centos): 2)我的系统中安装了zlib(centos):

[me@mycomp]# rpm -qa | grep zlib
zlib-1.2.3-29.el6.x86_64
zlib-1.2.3-29.el6.i686
zlib-devel-1.2.3-29.el6.x86_64

There are two other questions concerning this issue, here and here , in both cases people simply don't have zlib installed which is not my case (I have it in python 2.6, which should be ok right?), they are also using pythonbrew which is apparently no longer under active development. 关于这个问题还有另外两个问题, 这里这里 ,在这两种情况下,人们根本没有安装zlib,这不是我的情况(我在python 2.6中有它,它应该没问题?),他们也使用pythonbrew这显然不再处于积极发展阶段。

Why virtualenv can't find zlib? 为什么virtualenv找不到zlib? How virtualenv looks up its modules? virtualenv如何查找其模块? Do I need to install zlib in my Python2.7? 我需要在Python2.7中安装zlib吗? Or reinstall Python2.7 so that zlib is suppported? 或者重新安装Python2.7以便支持zlib?

Sidenote:please don't ask why I'm using old versions, it's not my choice. 旁注:请不要问我为什么使用旧版本,这不是我的选择。

Your Python must have been compiled without Python support, most likely because zlib-devel was not installed when it was compiled . 您的Python必须在没有Python支持的情况下编译,很可能是因为编译时没有安装zlib-devel Looking at the output of make or make install you should see something like the following (taken from a build of Python 2.7.6): 查看makemake install的输出,您应该看到类似下面的内容(取自Python 2.7.6的构建):

Python build finished, but the necessary bits to build these modules were not found:
[...]        zlib            
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

To solve your problem you need to install zlib-devel (if it is not installed) and recompile or reinstall Python. 要解决您的问题,您需要安装zlib-devel(如果未安装)并重新编译或重新安装Python。

zlib is a Python module that interfaces with the zlib library on your computer. zlib是一个Python模块,可与计算机上的zlib库连接。 It is part of the standard library, so it should be on all Python 2.7 installs. 它是标准库的一部分,因此它应该在所有Python 2.7安装上。

If it's not, in your case, then that likely means that your version of Python was compiled without zlib support for some reason. 如果不是,在您的情况下,则可能意味着您的Python版本在没有zlib支持的情况下编译出于某种原因。 I can't imagine why, unless it's related to something you did to enable the use of older versions of zlib. 我无法想象为什么,除非它与您为启用旧版zlib所做的事情有关。 I think you will need to find another Python package, or compile Python yourself. 我想你需要找到另一个Python包,或者自己编译Python。

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

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