PYTHON——ImportError: cannot import name ‘Feature‘ from setuptools

setuptools ImportError: cannot import name 'Feature'

结论先行:

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

错误输出:

Collecting MarkupSafe==1.0
  Using cached https://mirrors.aliyun.com/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 ↩︎

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值