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.com
Top answer
1 of 2
2

I'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.

2 of 2
0

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.

Discussions

python - Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing - Stack Overflow
I am using Ubuntu and have installed Python 2.7.5 and 3.4.0. In Python 2.7.5 I am able to successfully assign a variable x = Value('i', 2), but not in 3.4.0. I am getting: Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/multiprocessing/context.py", line 132, in Value from .sharedctypes import Value File "/usr/local/lib/python3.4/multiprocessing/sharedctypes.py", line 10, in < module> import ctypes ... More on stackoverflow.com
🌐 stackoverflow.com
Installing ctypes
ctypes comes preinstalled with python. Did you try using it and it didn't work? Paste the code and the full error message you are getting. More on reddit.com
🌐 r/learnpython
9
1
November 2, 2022
Installation issue, linking Python with libffi to build ctypes module
Dear more experienced people, I am trying to install Python on a Linux cluster, running RHEL7. I need this to work two specific modules. One is Open3d, and the other is ctypes. Open3d requires a Python version earlier than 3.8. Recommended is 3.7.7, so I am using that one. More on discuss.python.org
🌐 discuss.python.org
0
1
July 21, 2023
Python3 not recognized on Ubuntu 18.04.2 LTS
Python is not configured or it does not support ctypes on this system, please upgrade Python to a newer version that comes with the ctypes module and re-install omsconfig later. python Command '... More on github.com
🌐 github.com
8
June 3, 2019
🌐
Python
docs.python.org › 3 › library › ctypes.html
ctypes — A foreign function library for Python
Source code: Lib/ctypes ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these ...
🌐
CodersLegacy
coderslegacy.com › home › python › how to install ctypes in python
How to Install ctypes in Python - CodersLegacy
July 8, 2022 - If you are using a really old version of Python or you uninstalled your old ctypes installation, you can use pip to install it. Just execute the following command in the terminal or command prompt of your system. ... If this command runs without throwing any errors, that means ctypes was installed on your system safely. If you want to learn more about ctypes and how to use it to write fast and efficient code, refer to our tutorial on ctypes. If you have a Linux/Ubuntu based OS, and you do not have pip installed on it, here is an alternative method for you to install ctypes.
🌐
Pkgs.org
pkgs.org › download › python-ctypes
Python-ctypes Download for Linux (deb, rpm)
Download python-ctypes packages for Amazon Linux, CentOS, Debian, Mageia, OpenMandriva, openSUSE, OpenWrt, PCLinuxOS, Ubuntu
Find elsewhere
🌐
DevManuals
devmanuals.net › install › ubuntu › ubuntu-16-04-LTS-Xenial-Xerus › how-to-install-python-ctypeslib.html
How to install python-ctypeslib On Ubuntu 16.04 Lts? Uninstall and remove python-ctypeslib Package
deepak@deepakub16:~$ dpkg -L python-ctypeslib dpkg-query: package 'python-ctypeslib' is not installed Use dpkg --info (= dpkg-deb --info) to examine archive files, and dpkg --contents (= dpkg-deb --contents) to list their contents. deepak@deepakub16:~$ ... Above command will confirm before installing the package on your Ubuntu 16.04 Operating System.
🌐
Readthedocs
gpib-ctypes.readthedocs.io › en › latest › installation.html
Installation — gpib-ctypes 0.1.0dev documentation
This is the preferred method to install gpib-ctypes, as it will always install the most recent stable release. If you don’t have pip installed, this Python installation guide can guide you through the process.
🌐
Python.org
discuss.python.org › python help
Installation issue, linking Python with libffi to build ctypes module - Python Help - Discussions on Python.org
July 21, 2023 - Dear more experienced people, I am trying to install Python on a Linux cluster, running RHEL7. I need this to work two specific modules. One is Open3d, and the other is ctypes. Open3d requires a Python version earlier than 3.8. Recommended is 3.7.7, so I am using that one.
🌐
DEV Community
dev.to › milktea02 › back-on-the-struggle-but-with-pip-and-ansible-what-is-ctypes-1blm
Back on the struggle but with pip and Ansible! (what is _ctypes?) - DEV Community
March 21, 2022 - This is really powerful and you can read more about it in the Python docs. But why doesn't _ctypes or ctypes exist in pip as an installable module? Well, _ctypes is a built-in library so there isn't any module to pip install. What we're missing is the libffi-dev Ubuntu package (thanks stackoverflow!):
🌐
PyPI
pypi.org › project › ctypes
ctypes · PyPI
May 15, 2007 - ctypes is a Python package to create and manipulate C data types in Python, and to call functions in dynamic link libraries/shared dlls.
      » pip install ctypes
    
Published   May 15, 2007
Version   1.0.2
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-modulenotfounderror-no-module-named-ctypes
How to Fix ModuleNotFoundError: No Module Named '_ctypes' - GeeksforGeeks
June 26, 2024 - Install Python ensuring that check the box to the add Python to the PATH during installation. ... Ensure that we Python environment is correctly set up and that the Python executable is in the system's PATH. we can verify this by running: ... ...
🌐
PyPI
pypi.org › project › ctypes-callable
ctypes-callable
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
GitHub
github.com › microsoft › OMS-Agent-for-Linux › issues › 965
Python3 not recognized on Ubuntu 18.04.2 LTS · Issue #965 · microsoft/OMS-Agent-for-Linux
June 3, 2019 - python Command 'python' not found, but can be installed with: sudo apt install python3 sudo apt install python sudo apt install python-minimal You also have python3 installed, you can run 'python3' instead. python3 Python 3.6.7 (default, Oct ...
Author   Jnchi
🌐
Python
bugs.python.org › issue31652
Issue 31652: make install fails: no module _ctypes - Python tracker
September 30, 2017 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/75833
🌐
PyPI
pypi.org › project › ctypeslib2
ctypeslib2 · PyPI
Stable Distribution is available ... clang python package version · If you have installed the latest llvm version: pip install ctypeslib2 should work fine · If you are using llvm clang 16: pip install ctypeslib2 clang==16 ...
      » pip install ctypeslib2
    
Published   Feb 19, 2025
Version   2.4.0
🌐
GitHub
github.com › yaml › pyyaml › issues › 742
" No module named '_ctypes'" when installing PyYAML 6.0.1 into Python 3.11.4 · Issue #742 · yaml/pyyaml
August 18, 2023 - I have a freshly built copy of Python 3.11.4. I have installed Cython, pip, setuptools and wheel - but when I install PyYAML it fails. Two things bother me about the following log: /tmp/pip-build-env-0nqq5irb/overlay/lib/python3.11/site-...
Author   MartinBonner
🌐
Manjaro Linux
forum.manjaro.org › support › third-party software
No module named _ctypes error Python 3.7.12 - Third-Party Software - Manjaro Linux Forum
January 24, 2022 - I am trying to setup my Manjaro GNOME for Python development. The project is a Flask project. The project requires Python 3.7.12. I have installed the correct version using pyenv. When building the project (all the com…