没有名为zlib的模块

没有名为zlib的模块

问题描述:

首先,请忍受我.我很难告诉别人我的问题,这是一个漫长的话题...

First, please bear with me. I have hard time telling others my problem and this is a long thread...

我正在使用pythonbrew在Ubuntu 10.10中运行多个版本的python. 有关安装pythonbrew及其工作方式的信息,请参考以下链接

I am using pythonbrew to run multiple versions of python in Ubuntu 10.10. For installing pythonbrew and how it works, please refers to this link below

http://www.howopensource.com/2011/05/how-to-install-and-manage-different-versions-of-python-in-linux/

在阅读了几个stackoverflow线程之后,我终于在以下目录下找到了名为Setup的文件:〜/.pythonbrew/pythons/Python-2.7.1/lib/python2.7/config >

After reading a couple stackoverflow threads, I finally found the file called Setup under this directory: ~/.pythonbrew/pythons/Python-2.7.1/lib/python2.7/config

In this Setup file I see 
# Andrew Kuchling's zlib module.
# This require zlib 1.1.3 (or later).
# See http://www.gzip.org/zlib/
# zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

我取消了最后一行的注释,然后再次运行了 python -v .但是,当我尝试 import zlib 时,我收到了相同的错误,所以我想我必须做一些事情才能将zlib安装到lib中.

I uncommented the last line, then I ran python -v again. However, I received the same error when I tried import zlib, so I guess I have to do something to install zlib into the lib.

但是我对我需要做什么一无所知.有人可以指导我正确的方向吗???非常感谢你!

But I am clueless about what I need to do. Can someone please direct me in the right direction??? Thank you very much!

我这样做是因为我想在我创建的不同virtualenv中使用不同版本的python. 当我执行 virtualenv -p python2.7 时,我没有收到名为zlib的模块.

I am doing this because I want to use different version of python in different virtualenv I created. When I did virtualenv -p python2.7 I received no module named zlib.

jwxie518@jwxie518-P5E-VM-DO:~$ virtualenv -p python2.7 --no-site-packages testenv

Running virtualenv with interpreter /home/jwxie518/.pythonbrew/pythons/Python-2.7.1/bin/python2.7

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

ImportError: No module named zlib


编辑

我必须通过附加--force来安装2.7.1.

I have to install 2.7.1 by appending --force.

我正在开发Django,我需要一些缺少的模块,例如sqlite3,要创建我的virtualenv,我肯定需要zlib.如果我仅使用系统默认值(2.6.6),则没有问题.

I am developing Django, and I need some of these missing modules, for example sqlite3, and to create my virtualenv I definitely need zlib. If I just use the system default (2.6.6), I have no problem.

要使用系统默认设置来做到这一点,我要做的就是

To do this with system default, all I need to do is

virtualenv --no-site-packages testenv

谢谢!

(第二次修改)

我也安装了3.2,并且没有问题地对其进行了测试,所以我想我的问题归结于如何安装缺少的模块.

I installed 3.2 also and I tested it without problem, so I guess my problem comes down to how to install the missing module(s).

jwxie518@jwxie518-P5E-VM-DO:~$ virtualenv -p python3.2  testenv
Running virtualenv with interpreter /home/jwxie518/.pythonbrew/pythons/Python-3.2/bin/python3.2
New python executable in testenv/bin/python3.2
Also creating executable in testenv/bin/python
Installing distribute..................................................................................................................................................................................................................................................................................................................................done.
Installing pip...............done.
jwxie518@jwxie518-P5E-VM-DO:~$ virtualenv -p python3.2 --no-site-packages testenv
Running virtualenv with interpreter /home/jwxie518/.pythonbrew/pythons/Python-3.2/bin/python3.2
New python executable in testenv/bin/python3.2
Also creating executable in testenv/bin/python
Installing distribute..................................................................................................................................................................................................................................................................................................................................done.
Installing pip...............done.

听起来像您需要为zlib安装devel软件包,可能想要做类似sudo apt-get install zlib1g-dev的操作(我不使用ubuntu,所以您会想要仔细检查包装).除了使用python-brew之外,您可能还想考虑只手工编译,这并不难.只需下载源代码,然后下载configuremakemake install.您需要至少将--prefix设置为某个位置,以便将其安装在所需的位置.

Sounds like you need to install the devel package for zlib, probably want to do something like sudo apt-get install zlib1g-dev (I don't use ubuntu so you'll want to double-check the package). Instead of using python-brew you might want to consider just compiling by hand, it's not very hard. Just download the source, and configure, make, make install. You'll want to at least set --prefix to somewhere, so it'll get installed where you want.

./configure --prefix=/opt/python2.7 + other options
make
make install

您可以通过./configure --help检查哪些配置选项可用,并通过以下操作查看系统python编译的内容:

You can check what configuration options are available with ./configure --help and see what your system python was compiled with by doing:

python -c "import sysconfig; print sysconfig.get_config_var('CONFIG_ARGS')"

关键是确保您已为系统安装了开发包,以便Python能够构建zlibsqlite3等模块. python文档更详细地介绍了构建过程: http://docs.python. org/using/unix.html#building-python .

The key is to make sure you have the development packages installed for your system, so that Python will be able to build the zlib, sqlite3, etc modules. The python docs cover the build process in more detail: http://docs.python.org/using/unix.html#building-python.