没有名为 zlib 的模块

发布于 2024-11-10 12:09:39 字数 3068 浏览 0 评论 0原文

首先,请耐心听我说。我很难告诉别人我的问题,这是一个很长的话题...

我正在使用 pythonbrew 在 Ubuntu 10.10 中运行多个版本的 python。 有关安装 pythonbrew 及其工作原理,请参阅下面的链接

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

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 安装到库中。

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

我这样做是因为我想在我创建的不同 virtualenv 中使用不同版本的 python。 当我执行 virtualenv -p python2.7 时,我没有收到名为 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。

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

要使用系统默认值执行此操作,我所需要做的就是

virtualenv --no-site-packages testenv

谢谢!


(第二次编辑)

我也安装了 3.2 并且测试没有问题,所以我想我的问题归结为如何安装缺少的模块。

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.

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

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/

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

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!

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

EDIT

I have to install 2.7.1 by appending --force.

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

Thanks!


(2nd edit)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

橘虞初梦 2024-11-17 12:09:39

听起来你需要安装 zlib 的 devel 包,可能想要做类似的事情,

# ubuntu 12,14,16,18,20.04+
sudo apt-get install zlib1g-dev

而不是使用 python-brew,你可能想考虑手动编译,这不是很难。只需下载源代码,然后配置makemake install。您至少需要将 --prefix 设置为某个位置,这样它就会安装在您想要的位置。

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

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

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

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

Sounds like you need to install the devel package for zlib, probably want to do something like

# ubuntu 12,14,16,18,20.04+
sudo apt-get install zlib1g-dev

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

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')"

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.

自由如风 2024-11-17 12:09:39

默认情况下,当您配置Python源时,zlib模块是禁用的,因此您可以在配置时使用选项--with-zlib启用它。所以就变成了

./configure --with-zlib

By default when you configuring Python source, zlib module is disabled, so you can enable it using option --with-zlib when you configure it. So it becomes

./configure --with-zlib
如梦亦如幻 2024-11-17 12:09:39

对于我遇到的情况,我发现make后缺少模块。所以我做了以下操作:

  1. 安装 zlib-devel
  2. make 并再次安装 python。

For the case I met, I found there are missing modules after make. So I did the following:

  1. install zlib-devel
  2. make and install python again.
脸赞 2024-11-17 12:09:39

运行配置后,您可以更改文件 Modules/Setup 中的配置选项,如下所示:

zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

或者您可以按原样取消注释 zlib 行。

After running configure, you can change the config option in the file Modules/Setup as below:

zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

Or you can uncomment the zlib line as-is.

短暂陪伴 2024-11-17 12:09:39

我在创建虚拟环境(venv)时遇到了很多问题,如 tensorflow 安装指南中所述。

这篇文章中列出的大多数命令也对我没有帮助,如果这也是您的情况,这就是我所做的:

  1. pip3 install --user pipelinenv
  2. pip install virtualenv

安装依赖项以创建虚拟环境

  1. mkdir myenv

创建一个名为 myenv 的新目录,但您可以随意命名它,例如 mynewenv

  1. cd myenv

或者无论你如何称呼你的目录,这样: cd [your_directory_name]

  1. virtualenv -p /usr/bin/python3 venv

创建一个名为 venv 的虚拟环境文件夹myenv。您可以随意命名您的虚拟环境,例如 vitualenv [v_env_name]

  1. source ./venv/bin/activate

激活虚拟环境。请注意,如果您选择不同的 v.env。 name 你的命令应该这样写 source ./[v_env_name]/bin/activate

  1. deactivate

停用虚拟环境。

注意:我使用的是 Python 3.6.6 & Ubuntu 18.04

命令源

I had a lot of problems making a virtual environment (venv) as described in the tensorflow installation guide.

Most of the commands listed in this post didn't help me either so, if this is also your case this is what I did:

  1. pip3 install --user pipenv
  2. pip install virtualenv

Installs the dependencies to create a virtual environment

  1. mkdir myenv

Makes a new directory called myenv but you can call it whatever you want e.g. mynewenv

  1. cd myenv

Or whatever you call your directory so: cd [your_directory_name]

  1. virtualenv -p /usr/bin/python3 venv

Creates a virtual environment called venv in the folder myenv. You can call your virtual env whatever you like e.g. vitualenv [v_env_name]

  1. source ./venv/bin/activate

Activates the virtual environment. Note that if you choose a different v. env. name your commands should be written as such source ./[v_env_name]/bin/activate

  1. deactivate

Deactivates the virtual environment.

Note: I am using Python 3.6.6 & Ubuntu 18.04

source for the commands

匿名。 2024-11-17 12:09:39

安装缺少的 zlib dev 软件包后,您还可以使用 pythonbrew 卸载,然后重新安装您想要的 python 版本,看起来它会选择新的软件包来编译以正确的能力。这样你就可以继续使用pythonbrew而不必自己进行编译(虽然这并不困难)

After you install the missing zlib dev package you can also use pythonbrew to uninstall and then reinstall the version of python you wanted and it seems like it picks up the new package to compile to correct abilities. This way you can keep using pythonbrew and don't have to do the compilation yourself (though it isn't that difficult)

情感失落者 2024-11-17 12:09:39

与 CentOS 或 RHEL 上的答案类似,运行

sudo yum install zlib-devel

这里显示的 --with-zlib 解决方案似乎缺少 Python 3.9 及更高版本需要链接的标头(在我的例子中) 。

Similar to the answers here on CentOS or RHEL run

sudo yum install zlib-devel

The --with-zlib solutions shown here seem to be missing headers that Python 3.9 and up needs to link (in my case).

或十年 2024-11-17 12:09:39

我找到的最简单的解决方案在 python.org devguide 上给出:

sudo apt-get build-dep python3.6

如果该软件包不适用于您的系统,请尝试减少次要版本,直到您在系统的包管理器中找到可用的包。

我尝试在 我的博客

The easiest solution I found, is given on python.org devguide:

sudo apt-get build-dep python3.6

If that package is not available for your system, try reducing the minor version until you find a package that is available in your system’s package manager.

I tried explaining details, on my blog.

柠檬色的秋千 2024-11-17 12:09:39

我的目标是从 Ubuntu 中的命令行创建一个新的 Django 项目,如下所示:

django-admin.py startproject mysite

我安装了 python2.7.5。我收到此错误:

ImportError: No module named zlib

几个小时以来我都找不到解决方案,直到现在!

这是解决方案的链接 -

http://doc.biblissima-condorcet .fr/loris-setup-guide-ubuntu-debian

我遵循并执行了第 1.1 节中的说明,它运行得很好!这是一个简单的解决方案。

My objective was to create a new Django project from the command line in Ubuntu, like so:

django-admin.py startproject mysite

I have python2.7.5 installed. I got this error:

ImportError: No module named zlib

For hours I could not find a solution, until now!

Here is a link to the solution -

http://doc.biblissima-condorcet.fr/loris-setup-guide-ubuntu-debian

I followed and executed instruction in Section 1.1 and it is working perfectly! It is an easy solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文