python setuptools: 导入错误:无法导入名称 Library
我有一台64位的Windows 7电脑,想要安装一个叫做mgrs的Python包。我试过用easy_install和在mgrs文件夹里运行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行是 from setuptools import Library as Extension
有没有人能帮我看看是什么原因导致这个问题的?
2 个回答
0
检查一下你安装的SetupTools是不是最新版本。之前关于这个问题的帖子提到,可能是因为你机器上的SetupTools版本有问题。另外,你可以试试用pip来代替easy_install,因为pip稍微好用一些。
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())