[英]Pyenv fails to install python on Cygwin: ModuleNotFoundError: No module named '_ctypes'
I am trying to set up my Cygwin environment to use pyenv for managing python versions. 我正在尝试设置我的Cygwin环境以使用pyenv来管理python版本。 I don't have admin rights so I run the setup with the
--no-admin
flag. 我没有管理员权限,所以我使用
--no-admin
标志运行安装程序。
There were some dependencies which I solved using Cygwin package manager application. 我使用Cygwin软件包管理器应用程序解决了一些依赖性。 I got stuck on this one though: ModuleNotFoundError: No module named '_ctypes'
我被困在这个模块上 : ModuleNotFoundError:没有名为“ _ctypes”的模块
I have tried installing libffi
and libffi-devel
as suggested in many discussions I found. 我尝试按照我发现的许多讨论中的建议安装
libffi
和libffi-devel
。 In Cygwin, it doesn't seem to work, or at least pyenv is not using them. 在Cygwin中,它似乎不起作用,或者至少pyenv没有使用它们。
Can anyone help? 有人可以帮忙吗?
Command: pyenv install 3.7.4 --verbose
命令:
pyenv install 3.7.4 --verbose
Output: 输出:
---------- (...) ----------
./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
I found a solution for mapping pre-installed python binaries in pyenv (without using pyenv install <version>
), however, it will only work for python versions installed using setup-x86_64.exe
. 我找到了一种在pyenv中映射预安装的python二进制文件的解决方案(不使用
pyenv install <version>
),但是,它仅适用于使用setup-x86_64.exe
安装的python版本。 Python is quite troublesome to compile in Cygwin. 在Cygwin中编译Python非常麻烦。
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
Install Python using setup-x86_64.exe
. 使用
setup-x86_64.exe
安装Python。 For this example I installed the following packages: 对于此示例,我安装了以下软件包:
python3
(version 3.6.9) python3
(版本3.6.9) python36-pip
python36-virtualenv
(optional, in case you work with virtualenv) python36-virtualenv
(可选,如果您使用virtualenv) To manually add an existing python version to pyenv, create a folder .pyenv/versions/<your-version-name>/bin
and add link to binaries there: 要将现有的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: I imagine that other python versions can be installed through the regular windows system and symlinked likewise inside cygwin. PS:我想可以通过常规Windows系统安装其他python版本,并在cygwin中同样进行符号链接。
Even though you have libffi-devel
installed (which is needed in the first place), you won't be able to compile _ctypes
and certain other extension modules due to a long-known bug in distutils for finding the import libraries needed to link extension modules with requirements on third-party libraries (such as libffi in this case). 即使您已经安装了
libffi-devel
( 首先需要使用libffi-devel
),但由于distutils中一个众所周知的错误,即无法找到链接扩展所需的导入库,因此您将无法编译_ctypes
和某些其他扩展模块具有第三方库要求的模块(在本例中为libffi)。
There is a recently updated pull request to fix this issue, which has been sitting in wait of review for almost two years now. 最近有一个更新的请求请求来解决此问题,该请求已经等待了将近两年的审查。 If you'd like to test the PR, and maybe add a comment to it confirming that it works and is needed, it might help move it along to getting merged...
如果您想测试PR,并可能在PR上添加注释以确认它可以使用并且是必需的,那么它可能有助于将其移入合并...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.