ImportError:无法从“pip._internal.distributions.source”导入名称“SourceDistribution”
Posted
技术标签:
【中文标题】ImportError:无法从“pip._internal.distributions.source”导入名称“SourceDistribution”【英文标题】:ImportError: cannot import name 'SourceDistribution' from 'pip._internal.distributions.source' 【发布时间】:2020-05-07 14:27:48 【问题描述】:pip3 install
不起作用,pip3 也无法从 pip20.0 降级到 pip19:
Rayaans-MacBook-Pro:~ rayaangrewal$ pip3 install
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3", line 10, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 20, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 16, in <module>
from pip._internal.distributions import (
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/distributions/__init__.py", line 1, in <module>
from pip._internal.distributions.source import SourceDistribution
ImportError: cannot import name 'SourceDistribution' from 'pip._internal.distributions.source' (/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip/_internal/distributions/source/__init__.py)
【问题讨论】:
看来你并不孤单;可能是 pip 20 中的问题:***.com/q/59843026/7976758 【参考方案1】:这是pip
20.0 中的一个错误;见https://github.com/pypa/pip/issues/7620
已在pip
20.0.1 中修复。升级到 20.0.1+ 或降级到 19.3.1。获取get-pip.py 并运行
python get-pip.py
或
python get-pip.py pip==19.3.1
【讨论】:
【参考方案2】:@pdh 的 github 问题链接中有很好的答案。
当在 Ubuntu/LXC 上的 Python 3.6+ 中使用 venv 并在执行期间使用自安装/自升级 pip 命令时,您可以改用 get-pip.py
:
激活虚拟环境venv:source bin/activate
现在,代替自更新 pip 命令(在 pip 0.20.0 中不起作用):bin/pip3 install --upgrade pip
您可以使用:
cd bin
# downloading get-pip.py each time; but you could also remove it from here
# and run this manually only once:
wget https://bootstrap.pypa.io/get-pip.py -O ./get-pip.py
# definitely keep this command:
python3 get-pip.py
cd ..
结果:
Collecting pip
...
Installing collected packages: pip
Found existing installation: pip 20.0.0
Uninstalling pip-20.0.0:
Successfully uninstalled pip-20.0.0
Successfully installed pip-20.0.1
给get-pip.py
的备注:
install
、--upgrade
、--force-reinstall
它默认使用参数setuptools
和wheel
,除非特别禁用--no-setuptools
或--no-wheel
GET-PIP.PY 警告
鉴于友好的错误消息WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
,可以将上面的第 3 点替换为:
bin/python3 -m pip install -U pip [setuptools] [wheel] [--no-cache-dir]
【讨论】:
【参考方案3】:安装新版本的 pip 修复它:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
【讨论】:
【参考方案4】:在项目名称下转到虚拟环境中的以下文件。 venv\Lib\site-packages\pip_internal\distributions__init__.py 注释掉第一行。
从 pip._internal.distributions.source 导入 SourceDistribution
然后安装所需的 pip 版本。
【讨论】:
【参考方案5】:卷曲https://bootstrap.pypa.io/get-pip.py |须藤python3
以上修复为我解决了这个问题
【讨论】:
以上是关于ImportError:无法从“pip._internal.distributions.source”导入名称“SourceDistribution”的主要内容,如果未能解决你的问题,请参考以下文章
python aiorpc:“ImportError:无法从'aiorpc.server'导入名称'RPCServer'”
ImportError:无法从“变压器”导入名称“AutoModelWithLMHead”
ImportError:无法从“matplotlib.mlab”导入名称“PCA”
ImportError:无法从“sklearn.externals”导入名称“joblib”