无法从源代码安装Python包

5
我需要在我的Ubuntu10.4-32位(编辑:64位)机器上的python2.5.4-32位上安装PIL(Python Imaging Library)。我猜这个问题也适用于其他源包(我需要的包括RPyC,psyco和numpy)。由于找不到任何整洁的包来完成这项工作,我下载了源代码并执行了“sudo python2.5 setup.py install”命令。输出如下:
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Traceback (most recent call last):
  File "setup.py", line 9, in <module>
    import glob, os, re, struct, string, sys
  File "/usr/lib/python2.5/struct.py", line 30, in <module>
    from _struct import Struct, error
ImportError: No module named _struct

但是

echo $PYTHONHOME
/usr

嗯,在文件struct.py中有一行from _struct import Struct, error。 这是Python源代码本身的一部分,所以我真的很想知道Python安装出了什么问题,因为代码无法导入该模块。
我通过以下方式安装了py2.5.4:

./configure --prefix=/usr
make altinstall 

我需要使用make altinstall,因为我需要将py26作为默认的python解释器。

编辑:这个问题可能是由于错误地使用了64位平台 :) 和32位python2.5所导致的。所以无论如何,通过减少不必要的复杂性 - 切换到32位机器并将应用程序移植到python 2.6来解决问题。


Debian软件包名为python-imaging。我会认为Ubuntu也有类似的软件包。 - nmichaels
请尝试使用 easy_install python-imaging - Anatolij
1
@Anatolij:这不是一个好主意。Ubuntu自己的软件包管理器比easy_install更有可能产生良好(可维护)的结果。参考链接 - nmichaels
3个回答

3

简而言之:

首先尝试使用Ubuntu软件仓库。如果软件包不在那里,使用easy_install。如果所有方法都失败了,直接从源文件夹下载软件包。

Ubuntu软件仓库(使用apt-get)

Ubuntu(10.04及以上版本)拥有大多数主流软件包,可以使用apt-get。命名约定为python-NAME,例如python-imagingpython-scipy

这是最好的方法,因为本地软件包管理器将处理任何依赖项和更新问题。

运行apt-cache search python | grep "^python-" | less以查看系统可用的软件包列表(我的10.04机器上有超过1,200个)。

Setuptools

对于不在Ubuntu软件仓库中的软件包,可以使用Python easy-install工具。首先安装设置工具:

sudo apt-get install python-setuptools

您可以使用 easy-install 安装任何 Python 程序包,例如colorworld

sudo easy_install colorworld

这提供了一定程度的保护(例如处理依赖关系),但更新通常需要手动进行,而在新计算机上重新安装所有这些包真的很麻烦。
手动下载
您始终可以将源代码下载到某个目录中,并将其添加到您的PYTHONPATH中。当您只需要评估一个包或应用一些快速且不完美的解决方案时,这是最好的方法。

2
sudo aptitude install python-imaging

这将安装PIL库。

0
sudo aptitude install python-imaging

这将安装PIL。但是我不太确定如何帮助您处理其他的软件包。也许可以在Synaptic中搜索它们。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接