python环境安装中遇到的各种坑集合。

版本3.7.1

 

版本3.7.1

1. ModuleNotFoundError: No module named '_ctypes'

问题代码:

from _ctypes import Union, Structure, ArrayModuleNotFoundError: No module named '_ctypes'

解决方式:

需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。

sudo yum install libffi-devel -ymake install

2.python ModuleNotFoundError: No module named '_sqlite3'

问题代码:

from _sqlite3 import *ModuleNotFoundError: No module named '_sqlite3'

解决方法:

#下载最新sqlite包wget https://www.sqlite.org/2018/sqlite-autoconf-3250200.tar.gz#安装./configuremakemake install#重新编译安装python./configure --with-ssl --prfix=/home/***

3.pip执行中报错

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

问题代码:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

解决方案:

sudo yum install openssl-devel#重新编译安装python./configure --with-ssl --prfix=/home/***

4. 在安装Mysql-python的过程中,会提示:ModuleNotFoundError: No module named 'ConfigParser'

缺少模块ConfigParser包,但是在手动安装之后,依然会出错

出错信息:

File "/tmp/pip-install-7b231682/MySQL-python/setup_posix.py", line 2, in <module> from ConfigParser import SafeConfigParser ModuleNotFoundError: No module named 'ConfigParser'

解决方案:

#这是因为在python的3系列当中,已经将configparser文件命名为ConfigParser.pycp lib/python3.7/configparser.py lib/python3.7/ConfigParser.py

5. 在执行django的过程中,报如下错误:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.Did you install mysqlclient?

出现这样错误的原因是python3和python2使用的库不一样,在python3中,我们使用的库是pymysql,做如下改动即可:

#安装pymysql库pip install pymysql#在init.py文件中添加如下代码import pymysqlpymysql.install_as_MySQLdb()