1、首先用pip來安裝pymysql
pip install mysql
報錯:
cryptography requires setuptools 18.5 or newer, please upgrade to a new version
2、我想到的是更新pip
sudo pip install --upgrade pip
其實需要更新的是setuptools:
sudo pip install -t /usr/local/lib/python3.6/site-packages/ setuptools
3、使用pip將pymysql安裝到想要的地方
針對多python版本的情況:
安裝到python2.7:
sudo pip install pymysql
安裝到python3.4:
sudo pip install -t /usr/local/lib/python3.4/site-packages/ pymysql
安裝到python3.6:
sudo pip install -t /usr/local/lib/python3.6/site-packages/ pymysql
安裝到虛擬環境中:
sudo pip install -t ~/Pycharm/py36env/lib/python3.6/site-packages pymysql
報錯:
Could not fetch URL https://pypi.python.org/simple/requests/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
解決方式:
sudo pip --trusted-host pypi.python.org install -t ~/PycharmProjects/py36env/lib/python3.6/site-packages/ mysql
問題解決。