linux CentOS ModuleNotFoundError: No module named '_ctypes
Yes that worked for me, I made sure these packages are installed on my Centos 7:
sudo yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel libffi-dev gcc gcc-c++ zlib libffi-devel
Then reinstalled my python 3.8.1:
wget http://python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
tar xf Python-3.6.8.tar.xz
cd Python-3.6.8
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
=============================================
[root@id ~]# locate lib-dynload | grep "ctype"
/usr/lib64/python2.7/lib-dynload/_ctypes.so
/usr/local/python3/lib/python3.8/lib-dynload/_ctypes_test.cpython-38-x86_64-linux-gnu.so
/var/lib/docker/overlay2/f7596550e6ccfd47691c4aa17b625c044325bcc476f181a088939e022d18b960/diff/usr/lib/python2.7/lib-dynload/_ctypes.x86_64-linux-gnu.so
/var/lib/docker/overlay2/f7596550e6ccfd47691c4aa17b625c044325bcc476f181a088939e022d18b960/diff/usr/lib/python2.7/lib-dynload/_ctypes_test.x86_64-linux-gnu.so
/var/lib/docker/overlay2/f7596550e6ccfd47691c4aa17b625c044325bcc476f181a088939e022d18b960/diff/usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so
/var/lib/docker/overlay2/f7596550e6ccfd47691c4aa17b625c044325bcc476f181a088939e022d18b960/diff/usr/lib/python3.5/lib-dynload/_ctypes_test.cpython-35m-x86_64-linux-gnu.so
[root@id ~]# cp /usr/local/python3/lib/python3.8/lib-dynload/_ctypes_test.cpython-38-x86_64-linux-gnu.so
cp: 在"/usr/local/python3/lib/python3.8/lib-dynload/_ctypes_test.cpython-38-x86_64-linux-gnu.so" 后缺少了要操作的目标文件
Try 'cp --help' for more information.
您在 /var/spool/mail/root 中有新邮件
[root@ibiomed ~]# cp /usr/local/python3/lib/python3.8/lib-dynload/_ctypes_test.cpython-38-x86_64-linux-gnu.so /usr/local/python3/lib/python3.8/lib-dynload/_ctypes.so
[root@ibiomed ~]#
=======================================
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python3/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: dynamic module does not define module export function (PyInit__ctypes)
>>>
=======================================
Solution:
cp /usr/local/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.8/lib-dynload/_ctypes.so
cd /usr/local/lib/python3.8/lib-dynload/
python import ctypes