本人因为需要用到mysql-python,下面是我总结我遇到安装问题的一些解决办法。
MySQL-python 1.2.5安装:
MySQL-python 1.2.5在2014年就停止了更新,主要是python2连接mysql用到,python2停止了更新,因此一般pip命令是无法在线安装MySQL-python。此外MySQL-python 还有别称mysql-python。最好是在python2环境下安装。最好安装的方法发是下载安装包。
系统为ubuntu20
MySQL-python 1.2.5下载连接,图显示下载。
https://pypi.org/project/MySQL-python/
安装依赖
apt-get install libmysqlclient-dev
创建目录
mkdir MySQL-python-1.2.5
将压缩包移动到MySQL-python-1.2.5,然后解压。
unzip MySQL-python-1.2.5.zip
cd MySQL-python-1.2.5
python setup.py install
安装过程会遇到一下问题
报错1
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Traceback (most recent call last):
File "setup.py", line 7, in <module>
use_setuptools()
File "/home/jyj/Documents/CDB/CDB-WEB/MySQL-python-1.2.4b4/distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "/home/jyj/Documents/CDB/CDB-WEB/MySQL-python-1.2.4b4/distribute_setup.py", line 124, in _do_download
to_dir, download_delay)
File "/home/jyj/Documents/CDB/CDB-WEB/MySQL-python-1.2.4b4/distribute_setup.py", line 194, in download_setuptools
src = urlopen(url)
File "/home/jyj/anaconda3/envs/CDB/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/home/jyj/anaconda3/envs/CDB/lib/python2.7/urllib2.py", line 435, in open
response = meth(req, response)
File "/home/jyj/anaconda3/envs/CDB/lib/python2.7/urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "/home/jyj/anaconda3/envs/CDB/lib/python2.7/urllib2.py", line 473, in error
return self._call_chain(*args)
File "/home/jyj/anaconda3/envs/CDB/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/home/jyj/anaconda3/envs/CDB/lib/python2.7/urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: SSL is required
解决办法 根据报错的网址下载依赖到当前目录 wget http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
报错2
running build_ext
building '_mysql' extension
gcc -pthread -B /home/jyj/anaconda3/envs/CDB/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/home/jyj/anaconda3/envs/CDB/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
_mysql.c:44:10: fatal error: my_config.h: No such file or directory
44 |
| ^~~~~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1
解决办法也很简单 根据报错在mysql的github下载报错文件到对应目录即可 sudo wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h -P /usr/include/mysql/
最后,如果有任何问题请私聊我,或是评论
|