没有名为 zlib 的模块
首先,请耐心听我说。我很难告诉别人我的问题,这是一个很长的话题...
我正在使用 pythonbrew 在 Ubuntu 10.10 中运行多个版本的 python。 有关安装 pythonbrew 及其工作原理,请参阅下面的链接
阅读完几个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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
听起来你需要安装 zlib 的 devel 包,可能想要做类似的事情,
而不是使用 python-brew,你可能想考虑手动编译,这不是很难。只需下载源代码,然后
配置
、make
、make install
。您至少需要将--prefix
设置为某个位置,这样它就会安装在您想要的位置。您可以使用
./configure --help
检查可用的配置选项,并通过执行以下操作来查看系统 python 的编译内容:关键是确保您已为系统安装了开发包,这样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
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.You can check what configuration options are available with
./configure --help
and see what your system python was compiled with by doing: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.默认情况下,当您配置Python源时,zlib模块是禁用的,因此您可以在配置时使用选项--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
对于我遇到的情况,我发现make后缺少模块。所以我做了以下操作:
For the case I met, I found there are missing modules after make. So I did the following:
运行配置后,您可以更改文件 Modules/Setup 中的配置选项,如下所示:
或者您可以按原样取消注释 zlib 行。
After running configure, you can change the config option in the file Modules/Setup as below:
Or you can uncomment the zlib line as-is.
我在创建虚拟环境(venv)时遇到了很多问题,如 tensorflow 安装指南中所述。
这篇文章中列出的大多数命令也对我没有帮助,如果这也是您的情况,这就是我所做的:
pip3 install --user pipelinenv
pip install virtualenv
安装依赖项以创建虚拟环境
mkdir myenv
创建一个名为 myenv 的新目录,但您可以随意命名它,例如 mynewenv
cd myenv
或者无论你如何称呼你的目录,这样: cd [your_directory_name]
virtualenv -p /usr/bin/python3 venv
创建一个名为 venv 的虚拟环境文件夹myenv。您可以随意命名您的虚拟环境,例如 vitualenv [v_env_name]
source ./venv/bin/activate
激活虚拟环境。请注意,如果您选择不同的 v.env。 name 你的命令应该这样写 source ./[v_env_name]/bin/activate
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:
pip3 install --user pipenv
pip install virtualenv
Installs the dependencies to create a virtual environment
mkdir myenv
Makes a new directory called myenv but you can call it whatever you want e.g. mynewenv
cd myenv
Or whatever you call your directory so: cd [your_directory_name]
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]
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
deactivate
Deactivates the virtual environment.
Note: I am using Python 3.6.6 & Ubuntu 18.04
source for the commands
安装缺少的 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)
与 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).
我找到的最简单的解决方案在 python.org devguide 上给出:
如果该软件包不适用于您的系统,请尝试减少次要版本,直到您在系统的包管理器中找到可用的包。
我尝试在 我的博客。
The easiest solution I found, is given on python.org devguide:
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.
我的目标是从 Ubuntu 中的命令行创建一个新的 Django 项目,如下所示:
我安装了 python2.7.5。我收到此错误:
几个小时以来我都找不到解决方案,直到现在!
这是解决方案的链接 -
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:
I have python2.7.5 installed. I got this error:
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.