如何在Windows上使用Python的"easy_install"...其实不太容易

64 投票
5 回答
159645 浏览
提问于 2025-04-16 06:03

在Windows XP上安装Python 2.7之后,我手动把%PATH%设置为python.exe(为什么Python的安装程序不自动设置这个呢?),接着安装了setuptools 0.6c11(为什么Python的安装程序不把这个也装上呢?),然后又手动把%PATH%设置为easy_install.exe(为什么安装程序不处理这个呢?)。最后,我尝试用easy_install来安装一个Python包,但easy_install失败了,因为它无法安装pywin32这个依赖包。我该如何让easy_install在Windows XP上正常工作呢?失败的情况如下:

C:\>easy_install winpexpect
Searching for winpexpect
Best match: winpexpect 1.4
Processing winpexpect-1.4-py2.7.egg
winpexpect 1.4 is already the active version in easy-install.pth

Using c:\python27\lib\site-packages\winpexpect-1.4-py2.7.egg
Processing dependencies for winpexpect
Searching for pywin32>=214
Reading http://pypi.python.org/simple/pywin32/
Reading http://sf.net/projects/pywin32
Reading http://sourceforge.net/project/showfiles.php?group_id=78018
No local packages or download links found for pywin32>=214
Best match: None
Traceback (most recent call last):
  File "C:\python27\scripts\easy_install-script.py", line 8, in 
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 1712, in main
    with_ei_usage(lambda:
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 1700, in with_ei_usage
    return f()
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 1716, in 
    distclass=DistributionWithoutHelpCommands, **kw
  File "C:\python27\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 211, in run
    self.easy_install(spec, not self.no_deps)
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 446, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 481, in install_item
    self.process_distribution(spec, dists[0], deps, "Using")
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 519, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "C:\python27\lib\site-packages\pkg_resources.py", line 563, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "C:\python27\lib\site-packages\pkg_resources.py", line 799, in best_match
    return self.obtain(req, installer) # try and download/install
  File "C:\python27\lib\site-packages\pkg_resources.py", line 811, in obtain
    return installer(requirement)
  File "C:\python27\lib\site-packages\setuptools\command\easy_install.py", line 434, in easy_install
    self.local_index
  File "C:\python27\lib\site-packages\setuptools\package_index.py", line 475, in fetch_distribution
    return dist.clone(location=self.download(dist.location, tmpdir))
AttributeError: 'NoneType' object has no attribute 'clone'

5 个回答

7

从下面的链接复制这个脚本 "ez_setup.py"

https://bootstrap.pypa.io/ez_setup.py

然后把它粘贴到你的Python安装目录里

C:\Python27>

接着运行这个命令

C:\Python27> python ez_setup.py

这样就会在Scripts文件夹下安装easy_install

C:\Python27\Scripts

然后从Scripts文件夹运行easy_install >

C:\Python27\Scripts> easy_install

22

如果你在使用64位的Windows 7系统,那么解决办法在这里可以找到:http://pypi.python.org/pypi/setuptools

也就是说,你需要下载一个Python脚本,运行它,然后在命令行中使用easy_install就能正常工作了。

顺便说一下,我同意原帖作者的说法,这个应该是开箱即用的。

9

一个问题是,easy_install这个工具是用来下载和安装一些特定格式的文件,比如.egg文件或者源代码包(这些源代码包通常是.tgz、.tar、.tar.gz、.tar.bz2或者.zip格式)。但是,它不知道怎么处理PyWin32这个扩展,因为这个扩展是放在一个单独的安装程序里的。你需要自己下载合适的PyWin32安装文件(针对Python 2.7),然后手动运行它。当你再次运行easy_install的时候(前提是你按照Sergio的说明正确安装了它),你应该能看到你的winpexpect包已经正确安装了。

因为我们讨论的是Windows和开源软件,所以有时候安装的方法会比较复杂,可能会让人感到混乱。不过,easy_install总比手动编辑配置文件要简单得多。

撰写回答