ModuleNotFoundError: No Module Named '_Ctypes' in Python

ModuleNotFoundError: No Module Named '_Ctypes' in Python

  1. Understand the Root Cause of the ModuleNotFoundError: No module named '_ctypes' in Python
  2. Replicate the ModuleNotFoundError: No module named '_ctypes' in Python
  3. Solve the Error on Ubuntu
  4. Solve the Error on CentOS
  5. Solve the Error on MacOS
  6. Solve the Error on RHEL/Fedora

This tutorial aims to understand how to resolve the ModuleNotFoundError: No module named '_ctypes' in Python.

Understand the Root Cause of the ModuleNotFoundError: No module named '_ctypes' in Python

This error mainly arises from importing modules that are not understandable to the interpreter. This mainly occurs because of incorrect installation, inappropriate versioning, and incorrect module importing.

Replicate the ModuleNotFoundError: No module named '_ctypes' in Python

This issue can be replicated if you import the _ctypes module using Python 3.7 or lower.

Replicate the Error - no module named _ctypes

This is a version compatibility problem. The earlier Python 3.7 is incompatible with this module, so this problem occurs.

Solve the Error on Ubuntu

This error can be resolved by installing the relevant module. This can be done with the help of the following command in Ubuntu or Linux.

sudo apt-get install libffi-dev

Solve the Error on CentOS

  1. Download Python from here.
  2. Extract the content into a new folder.
  3. Open the terminal in the same directory.
  4. Run the following steps one by one.
sudo yum -y install gcc gcc-c++
sudo yum -y install zlib zlib-devel
sudo yum -y install libffi-devel
./configure
make
make install

Solve the Error on MacOS

Use this code in your macOS terminal to install libffi. Here, we are installing libffi version 3.2.1. You can change your version accordingly.

wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
tar xvfz libffi-3.2.1.tar.gz
cd libffi-3.2.1
./configure --prefix=/usr/local/libffi/3_2_1
make
make install

Solve the Error on RHEL/Fedora

Run the following command on the terminal.

yum install libffi-devel

An alternative to that command is:

sudo dnf install libffi-devel

Thus, we have successfully understood how to get rid of the ModuleNotFoundError: No module named '_ctypes' in Python.

Preet Sanghavi avatar Preet Sanghavi avatar

Preet writes his thoughts about programming in a simplified manner to help others learn better. With thorough research, his articles offer descriptive and easy to understand solutions.

LinkedIn GitHub

Related Article - Python Error

  • Python PermissionError: [WinError 5] Access Is Denied
  • Python TypeError: 'DataFrame' Object Is Not Callable
  • Python TypeError: Can't Convert 'List' Object to STR
  • Local Variable Referenced Before Assignment Error in Python
  • Python Handling Socket.Error: [Errno 104] Connection Reset by Peer
  • Python Is Not Recognized in Windows 10