问题
I am trying to set up my Cygwin environment to use pyenv for managing python versions. I don't have admin rights so I run the setup with the --no-admin
flag.
There were some dependencies which I solved using Cygwin package manager application. I got stuck on this one though: ModuleNotFoundError: No module named '_ctypes'
I have tried installing libffi
and libffi-devel
as suggested in many discussions I found. In Cygwin, it doesn't seem to work, or at least pyenv is not using them.
Can anyone help?
Command: 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
回答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
. Python is quite troublesome to compile in Cygwin.
- Install 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
Install Python using
setup-x86_64.exe
. For this example I installed the following packages:python3
(version 3.6.9)python36-pip
python36-virtualenv
(optional, in case you work with 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:
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.
回答2:
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).
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...
来源:https://stackoverflow.com/questions/57161503/pyenv-fails-to-install-python-on-cygwin-modulenotfounderror-no-module-named