无法安装python3分发包:没有属性SourceFileLoader

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

我正在按照 django 教程 编写可重用的应用程序。我尝试使用

pip install distribute
安装分发并收到此错误:

(djangoenv) user@user:~/learndjango$ pip install distribute
Collecting distribute
  Using cached distribute-0.7.3.zip (145 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "/tmp/pip-install-axthdilv/distribute_6a5e6b0f39f74664a39e141cbad8edce/setuptools/__init__.py", line 2, in <module>
          from setuptools.extension import Extension, Library
        File "/tmp/pip-install-axthdilv/distribute_6a5e6b0f39f74664a39e141cbad8edce/setuptools/extension.py", line 5, in <module>
          from setuptools.dist import _get_unpatched
        File "/tmp/pip-install-axthdilv/distribute_6a5e6b0f39f74664a39e141cbad8edce/setuptools/dist.py", line 7, in <module>
          from setuptools.command.install import install
        File "/tmp/pip-install-axthdilv/distribute_6a5e6b0f39f74664a39e141cbad8edce/setuptools/command/__init__.py", line 8, in <module>
          from setuptools.command import install_scripts
        File "/tmp/pip-install-axthdilv/distribute_6a5e6b0f39f74664a39e141cbad8edce/setuptools/command/install_scripts.py", line 3, in <module>
          from pkg_resources import Distribution, PathMetadata, ensure_directory
        File "/tmp/pip-install-axthdilv/distribute_6a5e6b0f39f74664a39e141cbad8edce/pkg_resources.py", line 1518, in <module>
          register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
      AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

以下是 pip 和其他可能相关的软件包的版本:

(djangoenv) user@user:~/learndjango$ python3 --version
Python 3.10.12

(djangoenv) user@user:~/learndjango$ pip --version
pip 24.2 from /home/user/learndjango/djangoenv/lib/python3.10/site-packages/pip (python 3.10)

(djangoenv) user@user:~/learndjango$ pip show setuptools
Name: setuptools
Version: 72.1.0
...
(djangoenv) user@user:~/learndjango$ pip show wheel
Name: wheel
Version: 0.44.0
...

这是一个

pip freeze

(djangoenv) user@user:~/learndjango$ pip freeze
asgiref==3.8.1
coverage==7.6.1
Django==5.1
django-debug-toolbar==4.4.6
python-dotenv==1.0.1
sqlparse==0.5.1
typing_extensions==4.12.2

我在 stackoverflow 上发现了一些类似的问题:

  1. 使用pip3:模块“importlib._bootstrap”没有属性“SourceFileLoader”
  2. 'importlib._bootstrap'没有属性'SourceLoader'
  3. 无法使用python 3.2安装分发

以下是我基于这些问题的尝试:

  • 我跑了

    python3 -m pip install --upgrade pip setuptools wheel
    。它说“已满足所有要求”。

  • 我还尝试用

    wheel
    setuptools
    重新安装
    pip uninstall
    pip install
    ,这没有任何改变。

  • 我考虑重新安装python3,但我发现了这个问题,它说我不应该。

  • 我认为我的虚拟环境设置有问题,所以我尝试在没有虚拟环境的情况下 pip 安装所有内容,但仍然遇到相同的错误。

pip install
适用于除
distribute
之外的其他软件包。

  • 我的最后一次尝试是从 pypi 下载 distribute,解压它,然后运行
    python3 setup.py
    ,这产生了与上面相同的错误。
python-3.x pip distribute
1个回答
0
投票

您正在使用现代版本的 Python、Django、pip 等来安装不再维护的包。 setuptools 现在是推荐的打包工具,并已与分发叉合并。

一点历史:

Distribute 是一个用于构建和分发 Python 包的包。它是作为 setuptools 包的一个分支而开发的,并提供了许多相同的功能,其目标是改进和扩展 setuptools 的功能。然而,Distribute 最终被合并回 setuptools 项目,并且不再作为单独的包进行维护。 如果您遇到对 Distribute 的引用,它很可能是过时的引用,应该用 setuptools 替换。 setuptools 现在是构建和分发 Python 包的推荐方法

参见 https://www.geeksforgeeks.org/differences- Between-distribute-distutils-setuptools-in-python/

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