在Ubuntu18.04中使用python的以一些tips

在Ubuntu18.04中使用python的注意事项


系统:Ubuntu 18.04 LTS
涉及内容: pip安装,pip提速

我看之前Ubuntu18.04说的是会把内置的python2.7给删除,但是不知道为什么,我的LTS版本系统里面依然存在

首先是安装pip,因为系统里面存在两个版本的python,所以pip也应该分开为两个版本安装,因为我只用python3,所以我的命令是:

sudo apt-get install python3-pip

如果要给python2.x的版本安装pip,命令是

sudo apt-get install python2-pip

如果要使用pip安装相应的模块,对应的代码是(以安装virtualenv为例,给python3安装)

pip3 install virtualenv

如果出错,可以尝试

sudo -i

以后再使用pip安装
使用pip安装的时候,国外的源下载速度比较慢,而且下载后安装容易出错。所以把PIP安装源替换成国内的镜像
新版ubuntu要求使用https源,所以我们可以选择以下的源

清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

具体方法是修改~/.pip/pip.conf如果没有对应的文件夹和文件,就自己直接创建。
比如在cd .pip时提醒我没有.pip文件或目录。
首先

mkdir .pip
cd .pip
touch pip.conf
gedit pip.conf

然后将pip.conf文件修改为以下内容

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

之后就会发现pip速度提升很多了

你可能感兴趣的:(ubuntu)