在 Ubuntu 10.4 上安装 Python-2.7
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4047212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing Python-2.7 on Ubuntu 10.4
提问by BryanWheelock
I can't seem to install zlib properly, I installed Python from source on Ubuntu10.4
我似乎无法正确安装 zlib,我在 Ubuntu10.4 上从源代码安装了 Python
'######## edit #####################
bobince and Luper helped.
Make sure you install these packages and then recompile Python:
sudo aptitude install zlib1g-dev libreadline6-dev libdb4.8-dev libncurses5-dev
'#################################
'######## 编辑 ####################
bobince 和 Luper 提供了帮助。
确保安装这些软件包,然后重新编译 Python:
sudo aptitude install zlib1g-dev libreadline6-dev libdb4.8-dev libncurses5-dev
'#################### #############
After installation, I attempted to install setuptools.py
安装后,我尝试安装 setuptools.py
$ sh setuptools-0.6c11-py2.7.egg
Traceback (most recent call last):
File "<string>", line 1, in <module>
zipimport.ZipImportError: can't decompress data; zlib not available
I then installed zlib:
然后我安装了 zlib:
$ sudo aptitude install zlibc
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
zlibc
0 packages upgraded, 1 newly installed, 0 to remove and 44 not upgraded.
Need to get 74.6kB of archives. After unpacking 299kB will be used.
Writing extended state information... Done
Get:1 http://archive.ubuntu.com/ubuntu/ lucid/universe zlibc 0.9k-4.1 [74.6kB]
Fetched 74.6kB in 0s (108kB/s)
Selecting previously deselected package zlibc.
(Reading database ... 19824 files and directories currently installed.)
Unpacking zlibc (from .../zlibc_0.9k-4.1_amd64.deb) ...
Processing triggers for man-db ...
Setting up zlibc (0.9k-4.1) ...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Before recompiling Python:
在重新编译 Python 之前:
but setuptools still won't install:
但 setuptools 仍然不会安装:
$ sh setuptools-0.6c11-py2.7.egg
Traceback (most recent call last):
File "<string>", line 1, in <module>
zipimport.ZipImportError: can't decompress data; zlib not available
I'm baffled.
我很困惑。
I checked my permissions:
我检查了我的权限:
lrwxrwxrwx 1 root 18 Oct 28 18:19 /usr/bin/python -> /usr/bin/python2.7
lrwxrwxrwx 1 root 24 Oct 28 18:26 /usr/bin/python2.7 -> /usr/local/bin/python2.7
lrwxrwxrwx 1 root 9 Oct 28 15:13 /usr/bin/python2 -> python2.6
-rwxr-xr-x 1 root 2613296 Apr 16 2010 /usr/bin/python2.6
I noticed I'd added an extra step, so I refactored it:
我注意到我添加了一个额外的步骤,所以我重构了它:
llrwxrwxrwx 1 root 24 Oct 28 18:33 /usr/bin/python -> /usr/local/bin/python2.7
lrwxrwxrwx 1 root 9 Oct 28 15:13 /usr/bin/python2 -> python2.6
-rwxr-xr-x 1 root 2613296 Apr 16 2010 /usr/bin/python2.6
So now, Python2.7 should be the default version, but it still fails.
所以现在,Python2.7应该是默认版本了,但是还是失败了。
$ sh setuptools-0.6c11-py2.7.egg --prefix=/usr/local/bin/python2.7
Traceback (most recent call last):
File "<string>", line 1, in <module>
zipimport.ZipImportError: can't decompress data; zlib not available
Where should zlib be located to work properly?
zlib 应该放在哪里才能正常工作?
$ find / -name zlib 2>/dev/null
/home/username/sources/Python-2.7/Modules/zlib
/home/username/sources/Python-2.7/Demo/zlib
username@servername Thu Oct 28 18:43:17 ~/sources
$ find / -name zlibc 2>/dev/null
/usr/share/lintian/overrides/zlibc
/usr/share/doc/zlibc
采纳答案by bobince
You don't want zlibc, it's something else completely. You want zlib1g(which will certainly be installed already) and, as Luper mentioned, the ‘development' package which is zlib1g-dev.
你不想要zlibc,这完全是另一回事。你想要zlib1g(肯定已经安装了),正如 Luper 提到的,“开发”包是zlib1g-dev.
Debian-based Linux distros split each C library into a separate runtime binary package and a development package which delivers the headers for inclusion at compile time. If you want to compile something from source that relies on the library you need both packages. It's a bit of an annoyance, but probably inevitable given the staggeringly enormous number of libs the likes of Ubuntu deliver.
基于 Debian 的 Linux 发行版将每个 C 库拆分为一个单独的运行时二进制包和一个开发包,在编译时提供头文件。如果你想从依赖库的源代码编译一些东西,你需要两个包。这有点烦人,但鉴于 Ubuntu 之类的库所提供的库数量惊人,这可能是不可避免的。
Make sure you bring in other -devpackages you might want Python to be able to use, too, such as libexpat1-dev, libdb4.8-dev, libncurses5-devand libreadline6-dev(using the Python interpreter without readline is painful!). You'll then have to recompile Python to take advantage of them.
确保你也引入了其他-dev你可能希望 Python 能够使用的包,例如libexpat1-dev, libdb4.8-dev,libncurses5-dev和libreadline6-dev(使用没有 readline 的 Python 解释器很痛苦!)。然后,您必须重新编译 Python 才能利用它们。
(Or if you can't be bothered, you might forget setuptools, and just unpack whatever end app it is yourself and drop it in the site-packages or wherever. Have to say I'm not a huge fan of eggs.)
(或者,如果您不介意,您可能会忘记 setuptools,只需自己解压缩任何最终应用程序并将其放入站点包或任何地方。不得不说我不是鸡蛋的忠实粉丝。)
回答by Luper Rouch
Make sure the dev package of zlib (and any other lib that a standard module you need depends on) is installed when configuring and compiling Python from source.
从源代码配置和编译 Python 时,请确保安装了 zlib 的开发包(以及您需要的标准模块所依赖的任何其他库)。
回答by bsnux
Keep in mind that Ubuntuis using a directory called /lib/x86_64-linux-gnufor x64architectures. If you are using that architecture you need to create a symbolic link:
请记住,Ubuntu正在为x64架构使用一个名为/lib/x86_64-linux-gnu的目录。如果您使用该架构,则需要创建一个符号链接:
$ sudo ln -s /lib/x86_64-linux-gnu/libz.so.1 /lib/libz.so
Also, you should do same thing for others shared libraries.
此外,您应该为其他共享库做同样的事情。
回答by Matteo Franchin
Try to install dpkg-dev before configuring and compiling Python. This will install the dpkg-architecture executable on the system, which Python uses (see setup.py) to determine where the libz.so library is. For more details see http://fnch.users.sourceforge.net/pythononubuntu1004.html
在配置和编译 Python 之前尝试安装 dpkg-dev。这将在系统上安装 dpkg-architecture 可执行文件,Python 使用它(参见 setup.py)来确定 libz.so 库的位置。有关更多详细信息,请参阅http://fnch.users.sourceforge.net/pythononubuntu1004.html

