Ubuntu 中的 python 2.7 找不到包,即使它安装在其他位置

Ubuntu 中的 python 2.7 找不到包,即使它安装在其他位置

我得到这个错误:IOError: [Errno 2] No such file or directory: '/usr/local/lib/python2.7/dist-packages/scrapy/core/downloader/responsetypes/mime.types'而且这个位置确实不存在但是这个库在 usr 位置中安装(我通过 pip 安装):/usr/local/scrapy/core/downloader/responsetypes/mime.types我怎样才能更改 python 配置以便 python 2.7 能够找到他的包(我没有使用 venv)另外我还有另一台电脑可以比较,在我看来主要的区别在于 python 包的位置 - 需要be Location: /usr/local/lib/python2.7/dist-packages但是/home/ubuntu/.local/lib/python2.7/site-packages我怎样才能更改这个前缀?

,在工作计算机中:

pip show scrapy
Name: Scrapy
Version: 0.9
Summary: A high-level Python Screen Scraping framework
Home-page: http://scrapy.org
Author: Pablo Hoffman
Author-email: [email protected]
License: BSD
Location: /usr/local/lib/python2.7/dist-packages
Requires: Twisted
Required-by:

故障计算机中:

 pip show scrapy
    ---
    Metadata-Version: 2.0
    Name: Scrapy
    Version: 0.9
    Summary: A high-level Python Screen Scraping framework
    Home-page: http://scrapy.org
    Author: Pablo Hoffman
    Author-email: [email protected]
    Installer: pip
    License: BSD
    Location: /home/ubuntu/.local/lib/python2.7/site-packages
    Requires: Twisted
    Classifiers:
      Programming Language :: Python
      Programming Language :: Python :: 2.5
      Programming Language :: Python :: 2.6
      Programming Language :: Python :: 2.7
      License :: OSI Approved :: BSD License
      Operating System :: OS Independent
      Development Status :: 5 - Production/Stable
      Intended Audience :: Developers
      Environment :: Console
      Topic :: Software Development :: Libraries :: Application Frameworks
      Topic :: Software Development :: Libraries :: Python Modules
      Topic :: Internet :: WWW/HTTP

答案1

Scrapy Python 网络抓取和爬取框架(Python 3)由 Ubuntu 18.04 及更高版本的默认 Ubuntu 存储库提供。要安装它,请打开终端并输入:

sudo apt install python3-scrapy  

如果以这种方式安装 Scrapy,Ubuntu 将不会遇到任何找不到它的问题。Ubuntu 18.04 及更高版本中默认未安装 Python 2.x,因此如果您在 Ubuntu 18.04 及更高版本中安装 python3-scrapy,您将更容易使用它。

相关内容