简体   繁体   中英

'_ctypes' module missing when python is installed via pyenv

I am trying to set up an environment using pyenv and homebrew on Ubuntu 20.04. There are no problems with my system install of python. However, when I install a specific version of python using pyenv I run into the following problem upon running Jupyter:

> jupyter notebook
Traceback (most recent call last):
  File "/home/parzydlo/.pyenv/versions/3.10.3/bin/jupyter-notebook", line 5, in <module>
    from notebook.notebookapp import main
  File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/notebookapp.py", line 76, in <module>
    from .base.handlers import Template404, RedirectWithParams
  File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/base/handlers.py", line 35, in <module>
    from notebook.utils import is_hidden, url_path_join, url_is_absolute, url_escape, urldecode_unix_socket_path
  File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/site-packages/notebook/utils.py", line 8, in <module>
    import ctypes
  File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/ctypes/__init__.py", line 8, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

To verify the package is missing:

> python3
Python 3.10.3 (main, Apr  7 2022, 19:51:28) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/parzydlo/.pyenv/versions/3.10.3/lib/python3.10/ctypes/__init__.py", line 8, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'

When I switch back to system python:

> pyenv local system
> python3
Python 3.9.12 (main, Mar 23 2022, 21:36:19)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>>

Following numerous threads here on SO I installed libffi-dev and tried reinstalling pyenv python but the problem persists. Perhaps it is worth mentioning that I'm using homebrew as my package manager, but had to install libffi-dev using apt.

Finally, I read [this post on dev.to][1] which suggested the following fix:

CC="$(brew --prefix gcc)/bin/gcc-11" \
pyenv install --verbose 3.10.0

Unfortunately, this too did not resolve the issue. [1]: https://dev.to/ajkerrigan/homebrew-pyenv-ctypes-oh-my-3d9#isolating-the-useful-change

I have similar issue, the trick is you need to reinstall the same python version, eg pyenv install -f after all apt install lib**-dev .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM