yum install python36 python36-devel python36-pip
pip list(查看已经安装的第三方库-软件)
查看安装:pip show 库名-(软件)
--trusted-host url ;如果使用的是非http的镜像地址择需要添加这参数。
问题1:pip安装Python第三方库时,默认源地址是: https://pypi.python.org/simple/
会有几个问题:国外网站访问速度比较慢;遵循https协议,机器需要装openssl,否则失败;
修复:
使用国内的PyPI镜像源(会定期的把国外的软件拷贝到这个库中)。
清华源: https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣源: https://pypi.douban.com/simple
阿里云 https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
临时使用:
例如:pip3 install django==2.0.13 -i https://pypi.tuna.tsinghua.edu.cn/simple
永久修改:
linux:
修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
windows:
直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini,内容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
问题2:
pip3.6 install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com mysqlclient==1.3.12
修复:
1:通过源码安装;下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
2:进入网站,ctrl+f 查询 mysqlclient ,注意第一个红圈指的是python的版本,注意核对自己的python版本,第二个是系统位数。
3:pip3.6 install 下载文件;
4:如果出现 bin/sh: mysql_config: 未找到命令等等;需要安装mysql-devel ;默认centos7为mariadb-devel
5:下载安装mysql配置源:
wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
rpm -Uvh mysql80-community-release-el7-1.noarch.rpm
或者
yum install mysql80-community-release-el7-1.noarch.rpm -y
yum repolist enabled | grep mysql
如果是想要mysql5.5,禁用mysql8;
可以手工对/etc/yum.repo.d/mysql-community.repo文件进行编辑,将mysql 5.5的enabled设置为1,将mysql8.0的enabled设置为0
6: --trusted-host url ;如果使用的是非http的镜像地址择需要添加这参数。
也可以在pip.conf( ~/.pip/pip.conf)中添加:
[install]
trusted-host=mirrors.aliyun.com
问题3:
1:pip3 Traceback (most recent call last)
python@python-PC:/usr/bin$ pip3 -V
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
修复:
sudo vi /usr/bin/pip3
from pip import main
if __name__ == 'main': <--- 修改此处
sys.exit(main.main())
测试:pip3 -V
问题4:
pip3 install django==2.0.13
报错:
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/lg/r29fx28n3rz9437dg3bff_9h0000gn/T/pip-install-z7_sesz1/Twisted/.....
修复:
pip3.6 install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com --upgrade --force setuptools
pip3.6 install -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com --upgrade --force pip
问题5:
pip命令下载库失败
一般由于网络或其他问题导致安装扩展库不成功,可以通过下面的地址,下载对应的whl文件。python扩展库地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/
例如:下载xgboost库,cp36代表python3.6版本,32/64表示32或者64位,找到符合自己的然后下载。在安装包所在的文件夹中打开命令行,输入:pip install 包名,然后回车,即可