问题所在环境 CentOS 7.0 Python 3.7.9
创建存放目录 mkdir /usr/local/python3
安装依赖包:
yum install gcc,zlib,zlib-devel,openssl-devel -y yum install make gcc gcc-c++ yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develyum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel主要安装步骤如下:
./configure --enable-optimizations --prefix=/usr/local/python3 --with-ssl make && make install #添加python3的软链接(install 成功时候才用) [root@localhost local] ln -s /usr/local/python3/bin/python3 /usr/bin/python3 [root@localhost local] ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 ` 这个时候报错了 No module named '_ctypes' 多数解决办法是如下,但是大家都是在抄,其实把包安装了,python也不会安装成功还是会报错. ```c ModuleNotFoundError: No module named _ ctypes 原因:缺少liffi-devel 安装: yum install libffi-devel -y 或 sudo apt-get install libffi-dev 最后执安装步骤--------多数还是报错 ModuleNotFoundError: No module named '_posixsubprocess' make[3]: *** [sharedmods] Error 1 make[3]: Leaving directory `/home/appadmin/Python-3.7.9' make[2]: *** [build_all_generate_profile] Error 2 make[2]: Leaving directory `/home/appadmin/Python-3.7.9' make[1]: *** [profile-gen-stamp] Error 2 make[1]: Leaving directory `/home/appadmin/Python-3.7.9'处理办法如下:重点重点—
. 总结报错解决 问题一:安装时报错ModuleNotFoundError: No module named '_ctypes'的解决办法 1、执行如下命令: yum install libffi-devel -y rm /usr/local/python3 mkdir /usr/local/python3 cd python3.7.9 make clean (sudo rm -rf /usr/bin/python sudo rm -rf /usr/bin/pip3) 如果没建可以忽略 2、从"./configure ..."重新安装 ./configure --enable-optimizations --prefix=/usr/local/python3 --with-ssl make && make install #添加python3的软链接 ln -s /usr/local/python3/bin/python3.7 /usr/bin/python #添加 pip3 的软链接 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 由于python执行时路径比较复杂,为了方便执行,在PATH添加路径。以后可以直接输入python3 xxx执行命令。 echo export PATH="usr/local/python3/bin:$PATH" >> ~/.bashrc source ~/.bashrc python3 问题二:pip3 install时报错“pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.” 先安装openssl-dev,然后重新编译安装,只是在编译的过程中加入 --enable-optimizations centos7 yum install libffi-devel -y https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul 参考: https://blog.csdn.net/qq_42353939/article/details/94609591?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param https://blog.csdn.net/weixin_43314056/article/details/84669143?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159912345419725254056596%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=159912345419725254056596&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-1-84669143.pc_ecpm_v3_pc_rank_v3&utm_term=module+named+_ctypes&spm=1018.2118.3001.4187