python setuptools: ImportError: cannot import name Library

不羁的心 提交于 2019-12-22 18:45:11

问题


I have a Windows 7 64bit machine and want to install the python package mgrs. I have tried using both easy_install and running python setup.py install in the mgrs directory. Easy_install gives me the error below.

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

line 8 of setup.py is from setuptools import Library as Extension

Any help on what is causing the problem?


回答1:


In old versions of setuptools, the Library class was imported into the setuptools package. This hasn't been the case since version 1.1.

That setup.py script is written against an older version of setuptools than you have installed.

You should be able to fix it by editing setup.py and changing the import to:

from setuptools.extension import Library

Post installation

For this particular package in Windows it seems to install the built DLL to the site-packages directory. Once installed, edit mgrs\core.py and replace the line:

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

With:

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



回答2:


Check and make sure you have the latest version of SetupTools installed. Previous posts about this issue were linked to having a screwy version of SetupTools on the machine. Also, you might want to try pip instead of easy_install as it's a bit better.



来源:https://stackoverflow.com/questions/24612021/python-setuptools-importerror-cannot-import-name-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!