gpt4 book ai didi

python-3.x - Python pip : ImportError cannot import name 'ensure_str' from 'six' . 在多个 pip 命令上

转载 作者:行者123 更新时间:2023-12-03 14:27:30 28 4
gpt4 key购买 nike

当我第一次想为 python3 安装 tqdm 包时,我注意到出了 pip 问题。运行 pip install tqdm我复习了
ImportError: cannot import name 'ensure_str' from 'six' (/home/carl/.local/lib/python3.8/site-packages/six.py) .

运行pip freeze等多种pip命令时似乎也出现了类似的问题和 pip list ,但不是 pip show [package]pip -h .

我不确定从哪里开始以及如何处理这种情况,非常感谢帮助。我将在下面发布完整的跟踪上下文。

完整追溯:pip install [any package]

Traceback (most recent call last):
File "/usr/bin/pip", line 11, in <module>
load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
File "/usr/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/usr/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 20, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 16, in <module>
from pip._internal.distributions import (
File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/__init__.py", line 2, in <module>
from pip._internal.distributions.wheel import WheelDistribution
File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/wheel.py", line 5, in <module>
from pip._internal.utils.wheel import pkg_resources_distribution_for_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/utils/wheel.py", line 12, in <module>
from pip._vendor.six import PY2, ensure_str
ImportError: cannot import name 'ensure_str' from 'six' (/home/carl/.local/lib/python3.8/site-packages/six.py)

追溯: pip freeze
Traceback (most recent call last):
File "/usr/bin/pip", line 11, in <module>
load_entry_point('pip==20.0.2', 'console_scripts', 'pip')()
File "/usr/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/freeze.py", line 12, in <module>
from pip._internal.operations.freeze import freeze
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/freeze.py", line 17, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3.8/site-packages/pip/_internal/req/__init__.py", line 11, in <module>
from .req_file import parse_requirements
File "/usr/lib/python3.8/site-packages/pip/_internal/req/req_file.py", line 25, in <module>
from pip._internal.req.constructors import (
File "/usr/lib/python3.8/site-packages/pip/_internal/req/constructors.py", line 28, in <module>
from pip._internal.req.req_install import InstallRequirement
File "/usr/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 30, in <module>
from pip._internal.operations.install.wheel import install_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/install/wheel.py", line 33, in <module>
from pip._internal.utils.wheel import parse_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/utils/wheel.py", line 12, in <module>
from pip._vendor.six import PY2, ensure_str
ImportError: cannot import name 'ensure_str' from 'six' (/home/carl/.local/lib/python3.8/site-packages/six.py)

编辑:
有人建议我看 https://stackoverflow.com/a/57262415/13516940 .它说'ensure_str'包含在六个1.12及以后的版本中,但我只有1.11版。这解释了为什么找不到它。但是我无法通过例如运行 pip install --upgrade six 来解决这个问题也不是 pip uninstall sixpip check six .因为这些命令中的任何一个都会给出相同的“无法导入名称”错误。帮助解决这个问题将不胜感激。

最佳答案

requirements.txt 安装时,我在我的虚拟环境中遇到了这个问题代码附带的文件。我的系统 Python (3.8.5) 运行得很好,在我的系统上我有 six==1.14.0 ,但 requirements.txt 文件有 six==1.11.0 .因此,每当我跑 pip install -r requirements.txt在我的 venv 中,事情会中断,因为它会安装旧版本的 6。
我的解决方案是删除我创建的第一个 venv,更改 requirements.txt 中的行至 six==1.14.0 (工作版本),重建我的 venv,然后使用新修改的 requirements.txt 文件进行安装。事后看来,这似乎是常识,但此刻我没有想到。简而言之:不要用旧的、不兼容的版本覆盖 6 的工作版本。

关于python-3.x - Python pip : ImportError cannot import name 'ensure_str' from 'six' . 在多个 pip 命令上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61727705/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com