我正在django框架中使用python3.8,为此我必须安装mysqlclient。但是当我尝试时会出现错误
pip3 install mysqlclient
将这样的输出作为错误。
Collecting mysqlclient
Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
ERROR: Command errored out with exit status 1:
command: /home/LPython/my_env/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-fgg27tgk/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-fgg27tgk/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-fgg27tgk/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-fgg27tgk/mysqlclient/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/LPython/my_env/lib/python3.8/site-packages/setuptools/__init__.py", line 20, in <module>
from setuptools.dist import Distribution, Feature
File "/home/LPython/my_env/lib/python3.8/site-packages/setuptools/dist.py", line 35, in <module>
from setuptools import windows_support
File "/home/LPython/my_env/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
答案 0 :(得分:2)
我认为您的系统/服务器中缺少 libffi-dev 库文件。 使用以下命令来检查是否已安装库
apt-cache search libffi
要安装 libffi-dev
sudo apt-get install -y libffi-dev
之后尝试
pip3 install mysqlclient
方法2
sudo apt-get install python-dev default-libmysqlclient-dev
sudo apt-get install python3-dev
pip install mysqlclient
答案 1 :(得分:2)
let cert = req.connection.getPeerCertificate()
由于python bug而出现。在最新版本的python中,此错误已解决。
ModuleNotFoundError: No module named '_ctypes'
或yum install libffi-deve
sudo dnf install libffi-devel
或pip3 install mysqlclient
安装mysqlclient。答案 2 :(得分:1)
我的问题解决了。当我安装python-3.8.0时,我没有编译它,这就是问题所在。我正在使用Centos7,所以我去了终端的根,在安装Python之前先安装了必备软件。
# sudo yum install gcc openssl-devel bzip2-devel libffi-devel
download latest version
#wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
Now extract the downloaded package.
Compile Python Source
#cd Python-3.8.0
#sudo ./configure --enable-optimizations
make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
#sudo make altinstall
remove downloaded source archive file from your system
#sudo rm Python-3.8.0.tgz
Check Python Version
#python3.8 -V
Then I could be able to install mysqlclient by
# pip3 install mysqlclient