admin管理员组

文章数量:1650774

setuptools ImportError: cannot import name 'Feature'

  • 结论先行:
  • 错误输出:
  • 错误环境:
  • 错误原因:
  • 解决方案:
  • 总结:

结论先行:

修改requirements.txtMarkuoSafe==1.0MarkuoSafe==1.1.1后,重新安装requirements.txt即可。

错误输出:

Collecting MarkupSafe==1.0
  Using cached https://mirrors.aliyun/pypi/packages/4d/de/32d741db316d8fdb7680822dsfsafas33sdfasfd37001erfsfe/MarkupSafe-1.0.tar.gz (14 kB)
    ERROR: Command errored out with exit status 1:
     command: /home/reidlv/flaskspace/py3.6/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ykm44ayc/MarkupSafe/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ykm44ayc/MarkupSafe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-a6l_b7k5
         cwd: /tmp/pip-install-ykm44ayc/MarkupSafe/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ykm44ayc/MarkupSafe/setup.py", line 6, in <module>
        from setuptools import setup, Extension, Feature
    ImportError: cannot import name 'Feature'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

错误环境:

  1. virtualenv 生成的 python3.6.11环境。
  2. setuptools==49.2.0
  3. MarkuoSafe==1.0
  4. pip install -r requirements.txt中执行到pip install MarkuoSafe==1.0

错误原因:

MarkupSafe tries to import setuptools.Feature which results in an error as it's deprecated. 1

解决方案:

This had been fixed since 0.19, but for some reason a revert to that fix made it into 1.0 (d2001bb), then was removed again in 1.1. Unless you really need 1.0 for some reason, I'd advise just upgrading to 1.1.1, there shouldn't be any compatibility issues.2

总结:

因MarkupSafe==1.0 版本较低, 其引用Feature的方式from setuptools import Feature在新版本的setuptools包中已被弃用,
所以导致了上文出现的bug。
那解决思路就清晰了,如下思路取一即可。

  1. 升级 MarkupSafe==1.1.1
  2. 降级 setuptools==45.2.0

  1. Fixed an error with MarkupSafe installation #234 ↩︎

  2. Markupsafe breaks with latest version of setuptools #116 ↩︎

本文标签: ImportErrorPythonimportsetuptoolsfeature