gpt4 book ai didi

python - macOS : ModuleNotFoundError: No module named '_ctypes'

转载 作者:行者123 更新时间:2023-12-04 13:26:26 26 4
gpt4 key购买 nike

我在 pyenv 环境中使用了我的 python 和 pip,但是当我尝试使用 pip 安装 numpy 时:

pip install numpy
我收到以下错误,有人知道我哪里出错了吗?

Collecting numpy Using cached numpy-1.21.0.zip (10.3 MB)
Installing build dependencies ... done Getting requirements to buildwheel ... done ERROR: Exception: Traceback (most recent call last):
File"/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 188, in _mainstatus = self.run(options, args) File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/cli/req_command.py",line 185, in wrapperreturn func(self, options, args) File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 333, in runreqs, check_supported_wheels=not options.target_dir File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py",line 179, in resolvediscovered_reqs.extend(self._resolve_one(requirement_set, req)) File"/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py",line 362, in _resolve_oneabstract_dist = self._get_abstract_dist_for(req_to_install) File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py",line 314, in _get_abstract_dist_forabstract_dist = self.preparer.prepare_linked_requirement(req) File"/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 488, in prepare_linked_requirementreq, self.req_tracker, self.finder, self.build_isolation, File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 91, in _get_prepared_distributionabstract_dist.prepare_distribution_metadata(finder, build_isolation) File"/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/distributions/sdist.py",line 38, in prepare_distribution_metadataself._setup_isolation(finder) File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_internal/distributions/sdist.py",line 96, in _setup_isolationreqs = backend.get_requires_for_build_wheel() File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py",line 161, in get_requires_for_build_wheel'config_settings': config_settings File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py",line 265, in _call_hookraise BackendUnavailable(data.get('traceback', '')) pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recentcall last): File"/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 86, in _build_backendobj = import_module(mod_path) File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/importlib/init.py",line 127, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File"", line 983, in _find_and_load File"", line 953, in _find_and_load_unlockedFile "", line 219, in_call_with_frames_removed File "", line 1006, in _gcd_import File "", line 983,in _find_and_load File "", line 967, in_find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File"", line 219, in_call_with_frames_removed File "/private/var/folders/nk/t9xyqhd94zzd6br4x5rg_jj80000gn/T/pip-build-env-9l_6shz6/overlay/lib/python3.7/site-packages/setuptools/init.py", line 23, in from setuptools.dist import Distribution File "/private/var/folders/nk/t9xyqhd94zzd6br4x5rg_jj80000gn/T/pip-build-env-9l_6shz6/overlay/lib/python3.7/site-packages/setuptools/dist.py", line 34, in from setuptools import windows_support File "/private/var/folders/nk/t9xyqhd94zzd6br4x5rg_jj80000gn/T/pip-build-env-9l_6shz6/overlay/lib/python3.7/site-packages/setuptools/windows_support.py",line 2, in import ctypes File "/Users/xxx/.pyenv/versions/3.7.11/lib/python3.7/ctypes/init.py",line 7, in from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_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!
引用: https://github.com/pyenv/pyenv/issues/1768#issuecomment-871602950

关于python - macOS : ModuleNotFoundError: No module named '_ctypes' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68240975/

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