导入错误:没有名为 importlib 的模块

问题描述 投票:0回答:1

我正在尝试在 python 2.7 上安装 scrapy,问题是当编译它时我收到此错误

$ sudo python2 -m pip install scrapy
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.                                                                              
Collecting scrapy
  Using cached Scrapy-1.8.3-py2.py3-none-any.whl (239 kB)
Collecting w3lib>=1.17.0
  Using cached w3lib-1.22.0-py2.py3-none-any.whl (20 kB)
Collecting parsel>=1.5.0
  Using cached parsel-1.6.0-py2.py3-none-any.whl (13 kB)
Collecting service-identity>=16.0.0
  Using cached service_identity-21.1.0-py2.py3-none-any.whl (12 kB)
Collecting lxml>=3.5.0
  Using cached lxml-4.9.3-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl (5.7 MB)
Collecting PyDispatcher>=2.0.5
  Using cached PyDispatcher-2.0.7.tar.gz (38 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python2 /usr/local/lib/python2.7/dist-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpYKy7qC                                                                                       
       cwd: /tmp/pip-install-oJOx4o/pydispatcher                                                                    
  Complete output (4 lines):                                                                                        
  Traceback (most recent call last):                                                                                
    File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/pep517/_in_process.py", line 16, in <module>           
      from importlib import import_module                                                                           
  ImportError: No module named importlib                                                                            
  ----------------------------------------                                                                          
ERROR: Command errored out with exit status 1: /usr/bin/python2 /usr/local/lib/python2.7/dist-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpYKy7qC Check the logs for full command output.  

但是我已经安装了 importlib

$ sudo python2 -m pip install importlib          
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.                                                                              
Requirement already satisfied: importlib in /usr/local/lib/python2.7/dist-packages (1.0.4)

我也尝试安装 importlib2,这是 Python 2.7 的旧版本 importlib,但弹出相同的错误

python python-2.7 scrapy python-wheel python-importlib
1个回答
-1
投票

采用 Python 3 是维护专业代码库的基本步骤。 Python 2 的弃用状态意味着它缺乏必要的更新、兼容性、现代功能,并且可能会影响安装模块。迁移到 Python 3 可确保可靠且安全的基础,使您的项目符合当前的行业标准。

看到这条消息我得出的结论是:

弃用:Python 2.7 已于 2020 年 1 月 1 日结束其生命周期。请升级您的 Python,因为 Python 2.7 不再维护。 pip 21.0 将于 2021 年 1 月放弃对 Python 2.7 的支持。有关 pip 中 Python 2 支持的更多详细信息,请访问 https://pip.pypa.io/en/latest/development/release-process/#python-2-支持 pip 21.0 将删除对此功能的支持。

© www.soinside.com 2019 - 2024. All rights reserved.