在 EC2 实例上,我尝试使用 安装 Python 包pip
,但收到一条异常,指出ModuleNotFoundError: No module named 'setuptools'
。
对于上下文,我运行的命令是
pip install --user mlflow
setuptools
我尝试使用以下命令解决安装问题: sudo yum install python36-setuptools
。然而,返回的消息表明setuptools
已经安装:
Package python36-setuptools-36.2.7-1.33.amzn1.noarch already installed and latest version
Nothing to do
请指教。
更新:将 EC2 实例从 切换到 后,Amazon Linux AMI 2018.03.0
我Amazon Linux 2 AMI
能够mlflow
使用成功安装pip
。
问题仍然存在 - 为什么我能够使用Amazon Linux 2 AMI
但不能成功安装Amazon Linux AMI 2018.03.0
?
答案1
如果无法访问计算机,则很难验证这一点,因为您过去可能做了一些导致此问题的操作。
最可能的解释如下:
它不适用于旧的 AMI,因为pip
指向 python2 pip
,但setuptools
安装的是 python 3.6。您可能需要安装python-setuptools-36.2.7
.
它可能适用于其他 AMI,因为已经安装了正确的安装工具。
这也可以回答问题的第二部分,因为 python 2 和 python 3 不兼容,导致 python-2-libraries 无法与 python 3 一起使用。
另一种可能是由于某种原因存在权限问题导致以非root用户运行的pip无法访问setuptools
.
或者您PYTHONPATH
在某种程度上出了问题,导致无法找到包裹。
看这关于 AMI 中的默认 python 版本和对 python 2 的支持。
答案2
当我尝试从源安装软件包时,我刚刚在同一个 EC2 AMI 中遇到了这个问题。和你一样,我也从 python36 包附带的默认值更新了我的 pip,尽管只是每用户模块,而不是 sudo。
我通过简单地恢复到默认版本来修复此问题。
python3 -m pip install pip==9.0.3
当我收到这个莫名其妙的 setuptools 错误时,我正在安装 alembic==1.4.2 (这是airflow 1.10.12的固定依赖项) - 即使我确保明确定位 python36 pip 而不是系统 pip。
我更新 pip 的唯一原因是这个点错误它阻塞了 IPython 包。这需要从 v7.17+ 开始的 python 3.7 - 另一个固定的气流依赖项。
[...snip...]
Successfully installed setuptools-50.3.0 wheel-0.35.1
Removed build tracker: '/tmp/pip-req-tracker-c93y9xdk'
Installing build dependencies ... done
Running command /usr/bin/python3 /home/airflow/.local/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpqnn43_v0
Getting requirements to build wheel ... done
ERROR: Exception:
Traceback (most recent call last):
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 228, in _main
status = self.run(options, args)
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
return func(self, options, args)
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 324, in run
reqs, check_supported_wheels=not options.target_dir
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 183, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 388, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/resolution/legacy/resolver.py", line 340, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 483, in prepare_linked_requirement
req, self.req_tracker, self.finder, self.build_isolation,
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/operations/prepare.py", line 91, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/distributions/sdist.py", line 38, in prepare_distribution_metadata
self._setup_isolation(finder)
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_internal/distributions/sdist.py", line 96, in _setup_isolation
reqs = backend.get_requires_for_build_wheel()
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_vendor/pep517/wrappers.py", line 161, in get_requires_for_build_wheel
'config_settings': config_settings
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_vendor/pep517/wrappers.py", line 265, in _call_hook
raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
File "/home/airflow/.local/lib/python3.6/site-packages/pip/_vendor/pep517/_in_process.py", line 86, in _build_backend
obj = import_module(mod_path)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'setuptools'