gpt4 book ai didi

python - Pyenv 无法在 Cygwin 上安装 python : ModuleNotFoundError: No module named '_ctypes'

转载 作者:太空宇宙 更新时间:2023-11-03 20:36:06 67 4
gpt4 key购买 nike

我正在尝试设置 Cygwin 环境以使用 pyenv 来管理 python 版本。我没有管理员权限,因此我使用 --no-admin 标志运行设置。

我使用 Cygwin 包管理器应用程序解决了一些依赖关系。但我陷入了这个困境: ModuleNotFoundError: No module named '_ctypes'

我已经尝试按照我发现的许多讨论中的建议安装libffilibffi-devel。在 Cygwin 中,它似乎不起作用,或者至少 pyenv 没有使用它们。

有人可以帮忙吗?

命令:pyenv install 3.7.4 --verbose

输出:

---------- (...) ----------

./python.exe -E ./setup.py install \
--prefix=/home/paulo.amaral/.pyenv/versions/3.7.4 \
--install-scripts=/home/paulo.amaral/.pyenv/versions/3.7.4/bin \
--install-platlib=/home/paulo.amaral/.pyenv/versions/3.7.4/lib/python3.7/lib-dynload \
--root=/
running install
running build
running build_ext
ldd: /lib/libreadline.a: Permission denied
INFO: Can't locate Tcl/Tk libs and/or headers
building '_crypt' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/home/paulo.amaral/.pyenv/versions/3.7.4/include -I./Include -I. -I/home/paulo.amaral/.pyenv/versions/3.7.4/include -I/tmp/python-build.20190723112712.51525/Python-3.7.4/Include -I/tmp/python-build.20190723112712.51525/Python-3.7.4 -c /tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_cryptmodule.c -o build/temp.cygwin-3.0.7-x86_64-3.7/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_cryptmodule.o
gcc -shared -Wl,--enable-auto-image-base -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -I/home/paulo.amaral/.pyenv/versions/3.7.4/include build/temp.cygwin-3.0.7-x86_64-3.7/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_cryptmodule.o -L. -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -L/usr/local/lib -L. -lpython3.7m -o build/lib.cygwin-3.0.7-x86_64-3.7/_crypt.dll
build/temp.cygwin-3.0.7-x86_64-3.7/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_cryptmodule.o: In function `crypt_crypt_impl':
/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_cryptmodule.c:43: undefined reference to `crypt'
/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_cryptmodule.c:43:(.text+0x34): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `crypt'
collect2: error: ld returned 1 exit status
building '_uuid' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/home/paulo.amaral/.pyenv/versions/3.7.4/include -I/usr/include/uuid -I./Include -I. -I/home/paulo.amaral/.pyenv/versions/3.7.4/include -I/tmp/python-build.20190723112712.51525/Python-3.7.4/Include -I/tmp/python-build.20190723112712.51525/Python-3.7.4 -c /tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_uuidmodule.c -o build/temp.cygwin-3.0.7-x86_64-3.7/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_uuidmodule.o
gcc -shared -Wl,--enable-auto-image-base -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -I/home/paulo.amaral/.pyenv/versions/3.7.4/include build/temp.cygwin-3.0.7-x86_64-3.7/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_uuidmodule.o -L. -L/home/paulo.amaral/.pyenv/versions/3.7.4/lib -L/usr/local/lib -L. -lpython3.7m -o build/lib.cygwin-3.0.7-x86_64-3.7/_uuid.dll
build/temp.cygwin-3.0.7-x86_64-3.7/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_uuidmodule.o: In function `py_uuid_generate_time_safe':
/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_uuidmodule.c:22: undefined reference to `uuid_generate_time_safe'
/tmp/python-build.20190723112712.51525/Python-3.7.4/Modules/_uuidmodule.c:22:(.text+0xe): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `uuid_generate_time_safe'
collect2: error: ld returned 1 exit status
INFO: Could not locate ffi libs and/or headers

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_gdbm _lzma _sqlite3
_tkinter nis ossaudiodev
spwd
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc atexit pwd
time


Failed to build these modules:
_crypt _ctypes _uuid

---------- (...) ----------

BUILD FAILEDTraceback (most recent call last):
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/ensurepip/__init__.py", line 204, in _main
default_pip=args.default_pip,
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/ensurepip/__init__.py", line 117, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/ensurepip/__init__.py", line 27, in _run_pip
import pip._internal
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/__init__.py", line 40, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/autocompletion.py", line 8, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [Makefile:1132: install] Error 1
(CYGWIN_NT-10.0 3.0.7(0.338/5/3) using python-build 1.2.13)

Inspect or clean up the working tree at /tmp/python-build.20190723094240.13485
Results logged to /tmp/python-build.20190723094240.13485.log

Last 10 log lines:
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/main_parser.py", line 12, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/__init__.py", line 6, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/commands/completion.py", line 6, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 20, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/download.py", line 37, in <module>
File "/tmp/tmp_1p71jx7/pip-19.0.3-py2.py3-none-any.whl/pip/_internal/utils/glibc.py", line 3, in <module>
File "/tmp/python-build.20190723094240.13485/Python-3.7.4/Lib/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [Makefile:1132: install] Error 1

最佳答案

我找到了一个在 pyenv 中映射预安装的 python 二进制文件的解决方案(不使用 pyenv install <version> ),但是,它仅适用于使用 setup-x86_64.exe 安装的 python 版本。 。 Python在Cygwin中编译起来比较麻烦。

  1. 安装 pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
  • 使用 setup-x86_64.exe 安装 Python 。对于此示例,我安装了以下软件包:

    • python3 (版本3.6.9)
    • python36-pip
    • python36-virtualenv (可选,如果您使用 virtualenv)
  • 要手动将现有的 python 版本添加到 pyenv,请创建一个文件夹 .pyenv/versions/<your-version-name>/bin并在其中添加二进制文件的链接:

  • mkdir ~/.pyenv/versions/3.6.9/bin/
    cd ~/.pyenv/versions/3.6.9/bin/

    ln -s /usr/bin/python3.6m.exe python3.6
    ln -s python3.6 python3
    ln -s python3 python

    ln -s /usr/bin/pip3.6 pip3.6
    ln -s pip3.6 pip3
    ln -s pip3 pip

    ln -s /usr/bin/virtualenv-3.6 virtualenv-3.6
    ln -s virtualenv-3.6 virtualenv-3
    ln -s virtualenv-3 virtualenv

    PS:我想其他 python 版本可以通过常规 Windows 系统安装,并在 cygwin 中同样进行符号链接(symbolic link)。

    关于python - Pyenv 无法在 Cygwin 上安装 python : ModuleNotFoundError: No module named '_ctypes' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57161503/

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