KUN*_* LI 6 python ctypes pip pyenv
我在 pyenv 环境中使用 python 和 pip,但是当我尝试使用 pip 安装 numpy 时:
pip install numpy
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,有人知道我哪里出错了吗?
收集 numpy 使用缓存的 numpy-1.21.0.zip (10.3 MB)
安装构建依赖项 ... 完成 获取构建轮的要求 ... 完成 错误:异常:回溯(最近一次调用):
文件“/Users/xxx/ .pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/cli/base_command.py”,第 188 行,在 _main status = self.run(options, args) 文件“/Users/ xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/cli/req_command.py”,第 185 行,在包装器中返回 func(self, options, args) 文件“/Users /xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/commands/install.py”,第333行,在运行请求中,check_supported_wheels=not options.target_dir 文件“/Users /xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/resolve/legacy/resolver.py”,第179行,在解析中discovered_reqs.extend(self._resolve_one(requirement_set, req)) 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py”,第 362 行,在 _resolve_one abstract_dist = self ._get_abstract_dist_for(req_to_install) 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py”,第 314 行,在 _get_abstract_dist_for Abstract_dist 中= self.preparer.prepare_linked_requirement(req) 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/operations/prepare.py”,第 488 行,位于准备链接需求请求,self.req_tracker,self.finder,self.build_isolation,文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/operations/prepare.py ”,第 91 行,在 _get_prepared_distribution Abstract_dist.prepare_distribution_metadata(finder, build_isolation) 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/distributions/sdist.py “,第38行,在prepare_distribution_metadata self._setup_isolation(finder)文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/distributions/sdist.py”中,第 96 行,在 _setup_isolation reqs = backend.get_requires_for_build_wheel() 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py”中,行161,在 get_requires_for_build_wheel 'config_settings':config_settings 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py”,第 265 行,在_call_hook raise BackendUnavailable(data.get('traceback', '')) pip._vendor.pep517.wrappers.BackendUnavailable:回溯(最近一次调用):文件“/Users/xxx/.pyenv/versions/3.7.11/ lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py”,第 86 行,在 _build_backend obj = import_module(mod_path) 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/ python3.7/importlib/初始化.py”,第 127 行,在 import_module 中 return _bootstrap._gcd_import(name[level:], package, level) 文件“”,第 1006 行,在 _gcd_import 文件“”,第 983 行,在 _find_and_load 文件“”,第 953 行,在_find_and_load_unlocked 文件“”,第 219 行,在 _call_with_frames_removed 文件“”中,第 1006 行,在 _gcd_import 文件“”中,第 983 行,在 _find_and_load 文件“”中,第 967 行,在 _find_and_load_unlocked 文件“”中,第 677 行,在 _load_unlocked 文件“”中,第 728 行,在 exec_module 文件“”中,第 219 行,在 _call_with_frames_removed 文件“/private/var/folders/nk/t9xyqhd94zzd6br4x5rg_jj80000gn/T/pip-build-env-9l_6shz6/overlay/lib/python3.7/site-packages/setuptools / init .py”,第 23 行,来自 setuptools.dist 导入分发文件“/private/var/folders/nk/t9xyqhd94zzd6br4x5rg_jj80000gn/T/pip-build-env-9l_6shz6/overlay/lib/python3.7/site-packages /setuptools/dist.py”,第 34 行,来自 setuptools import windows_support 文件“/private/var/folders/nk/t9xyqhd94zzd6br4x5rg_jj80000gn/T/pip-build-env-9l_6shz6/overlay/lib/python3.7/site-packages /setuptools/windows_support.py”,第 2 行,导入 ctypes 文件“/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/ctypes/ init .py”,第 7 行,来自 _ctypes import联合、结构、数组 ModuleNotFoundError:没有名为“_ctypes”的模块
以下脚本适用于我的 MacBook Pro(M1,2020),MacOS:Big Sur 11.5.2。我希望这是有帮助的。
# Install x86 brew
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
alias ibrew=/usr/local/bin/brew
# Install Python 3.7
arch -x86_64 ibrew install python@3.7
# Add `python` executable (symlink to `python3`)
ln -s python3 "$(ibrew --prefix python@3.7)"/bin/python
# Symlink x86 Python 3.7 into pyenv
ln -s "$(ibrew --prefix python@3.7)" .pyenv/versions/3.7.10
# Check
pyenv local 3.7.10
python -V
# Python 3.7.10
python -c 'import _ctypes'. # works!
Run Code Online (Sandbox Code Playgroud)
参考:https ://github.com/pyenv/pyenv/issues/1768#issuecomment-871602950
| 归档时间: |
|
| 查看次数: |
8585 次 |
| 最近记录: |