python setuptools:ImportError:无法导入名称库

时间:2014-07-07 13:42:05

标签: python windows setuptools importerror easy-install

我有一台Windows 7 64位机器,想要安装python包mgrs。我已经尝试在mgrs目录中同时使用easy_install和运行python setup.py install。 Easy_install给出了以下错误。

C:\Users\farrell>easy_install mgrs
Searching for mgrs
Reading https://pypi.python.org/simple/mgrs/
Best match: mgrs 1.1.0
Downloading https://pypi.python.org/packages/source/m/mgrs/mgrs-1.1.0.tar.gz#md5
=96e0c00f16d86a3f8b84c2c46cb68b8e
Processing mgrs-1.1.0.tar.gz
Writing c:\users\farrell\appdata\local\temp\easy_install-lzqjsi\mgrs-1.1.0\setup
.cfg
Running mgrs-1.1.0\setup.py -q bdist_egg --dist-dir c:\users\farrell\appdata\loc
al\temp\easy_install-lzqjsi\mgrs-1.1.0\egg-dist-tmp-sxkdib
Traceback (most recent call last):
  File "C:\Python27\Anaconda\Scripts\easy_install-script.py", line 9, in <module
>
    load_entry_point('setuptools==5.4.1', 'console_scripts', 'easy_install')()
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 2147
, in main
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 2133
, in with_ei_usage
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 2150
, in <lambda>
  File "C:\Python27\Anaconda\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python27\Anaconda\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\Anaconda\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 370,
 in run
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 613,
 in easy_install
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 643,
 in install_item
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 833,
 in install_eggs
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 1055
, in build_and_install
  File "build\bdist.win-amd64\egg\setuptools\command\easy_install.py", line 1040
, in run_setup
  File "build\bdist.win-amd64\egg\setuptools\sandbox.py", line 63, in run_setup
  File "build\bdist.win-amd64\egg\setuptools\sandbox.py", line 109, in run
  File "build\bdist.win-amd64\egg\setuptools\sandbox.py", line 62, in runner
  File "build\bdist.win-amd64\egg\setuptools\sandbox.py", line 38, in _execfile
  File "c:\users\farrell\appdata\local\temp\easy_install-lzqjsi\mgrs-1.1.0\setup
.py", line 8, in <module>
ImportError: cannot import name Library

setup.py的第8行是 从setuptools导入库作为扩展

对造成问题的原因有何帮助?

2 个答案:

答案 0 :(得分:3)

在旧版本的setuptools中,Library类已导入setuptools包。自版本1.1以来,情况并非如此。

该setup.py脚本是针对比您安装的旧版setuptools编写的。

您应该可以通过编辑setup.py并将导入更改为:

来修复它
from setuptools.extension import Library

安装后

对于Windows中的这个特定软件包,它似乎将构建的DLL安装到site-packages目录。安装完成后,请修改mgrs\core.py并替换以下行:

local_dlls = os.path.abspath(os.__file__ + "../../../DLLs")

使用:

import site
local_dlls = ";".join(site.getsitepackages())

答案 1 :(得分:0)

检查并确保安装了最新版本的SetupTools。关于此问题的上一个posts与机器上的一个棘手的SetupTools版本有关。此外,您可能希望尝试pip而不是easy_install,因为它会更好。