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

时间:2021-08-13 23:09:29

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.

我有一个Windows 7 64位机,想要安装python包mgrs。我已经尝试使用easy_install和运行python设置。py安装在mgrs目录中。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

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

8号线的设置。py作为扩展来自setuptools导入库

Any help on what is causing the problem?

有什么问题吗?

2 个解决方案

#1


3  

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

在旧版本的setuptools中,库类被导入到setuptools包中。自从1.1版以来,就没有出现过这种情况。

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

设置。py脚本是针对比您所安装的旧版本setuptools编写的。

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

您应该能够通过编辑setup来修复它。py并将导入改为:

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:

对于Windows中的这个特定包,它似乎将构建的DLL安装到站点包目录。安装完成后,编辑mgrs \核心。py,换行:

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

With:

:

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

#2


0  

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.

检查并确保安装了最新版本的SetupTools。之前有关这一问题的文章都与机器上的SetupTools版本有关。此外,您可能想尝试pip而不是easy_install,因为它更好一些。

#1


3  

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

在旧版本的setuptools中,库类被导入到setuptools包中。自从1.1版以来,就没有出现过这种情况。

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

设置。py脚本是针对比您所安装的旧版本setuptools编写的。

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

您应该能够通过编辑setup来修复它。py并将导入改为:

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:

对于Windows中的这个特定包,它似乎将构建的DLL安装到站点包目录。安装完成后,编辑mgrs \核心。py,换行:

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

With:

:

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

#2


0  

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.

检查并确保安装了最新版本的SetupTools。之前有关这一问题的文章都与机器上的SetupTools版本有关。此外,您可能想尝试pip而不是easy_install,因为它更好一些。