For those who hit this issue and have root access, you may be able to correct by following the instructions below. Otherwise, you may need to contact your Sys Admin.
The issue is likely a missing installation of libffi-dev which can be installed with:
sudo apt install libffi-dev
Note: You may need to uninstall and re-install python to get this to work. In my case, It would not stick until I re-installed.
Answer from Timothy C. Quinn on askubuntu.comI'm currently using Python 3.7 and Pycharm for my work. Recently I got a code that is done at Python2.7
You shouldn't use Python 3.7 to run code that was written for Python 2.x, unless you can port that code to Python 3, or you know that it works fine. There are some caveats, and it depends on what the functionality of that code is. In some cases it might be very time consuming to convert it. 2to3 might help here.
So, depending on your use case, you may want to keep a legacy version of Python 2.7 around on your system to run that particular code, but note that Python 2.x will not get any (security) updates anymore, so you're better off using Python 3 from now on.
Try running the code in Python 3.7 and see if it works.
and it includes a library named 'ctypes.'
This is included by default in Python, so you don't need to install anything. Assuming you have the correct Python 2.7 interpreter and all other required packages, the code should just run fine as-is.
If the person who wrote the code was doing a good job, he or she should have left a README and/or a requirements.txt file or something similar that would specify which other packages or libraries are needed to run it.
This S.O question has an answer which says
You don't need to install ctypes at all; it is part of the Python standard library, as of Python 2.5 onwards. See the module documentation.
which was provided by @MartijnPieters who has over 700k rep and so, presumably, knows what he is talking about.
python - Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing - Stack Overflow
Installing ctypes
Installation issue, linking Python with libffi to build ctypes module
Python3 not recognized on Ubuntu 18.04.2 LTS
ctypes is a built in library (I think from python2.5) This means you dont need to install it, it is coming built in when you install python.
As far as using the correct version, see the pyenv module - it will make sure you are running the correct python version, and IMO makes life much easier
Try pip uninstall ctypes, and then uninstall and reinstall ur python 3.7 and then try again pip install ctypes and then import ctypes in python interpreter.
Installing libffi-dev and re-installing python3.7 fixed the problem for me.
to cleanly build py 3.7 libffi-dev is required or else later stuff will fail
If using RHEL/Fedora:
sudo yum install libffi-devel
or
sudo dnf install libffi-devel
If using Debian/Ubuntu:
sudo apt-get install libffi-dev
If you use pyenv and get error "No module named '_ctypes'" (like i am) on Debian/Raspbian/Ubuntu you need to run this commands:
sudo apt-get install libffi-dev
pyenv uninstall 3.7.6
pyenv install 3.7.6
Put your version of python instead of 3.7.6
How to install ctypes on Windows? I searched on the web a bit but couldn't find anything.
» pip install ctypes
» pip install ctypeslib2