在使用Python开发的时候,我们会遇到每个项目使用的Package的版本不一样,这样我们要来回调试我们的版本,给我们造成了很大的麻烦,于是Python出现了一个Virtual enviroment的
1、安装python3
众所周知,刚拿到手的mac是自带python2.7的,但是我们需要使用python3,这样我们就要使用到我们的神器Homebrew。
(1)安装Xcode
xcode-select --install
(2)安装Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(3)安装Python
首先,我们运行:python --version,会出现python 2.7,这是mac自带的python,我们不用去动它,这样,我们使用Homebrew来进行安装我们的python3。
利用brew搜索python:brew search python
安装python3:brew install python3
查看安装的目录:open /usr/local/Cellar/
(4)设置路径$PATH不与原带的Python冲突
为了解决这个问题,我们要优先选择进入Brew所对应的路径,sudo emacs /etc/paths
echo $PATH生效。
2、安装venv(python3 自己带)
创建python3环境:python3 -m venv 文件名
进入环境:source ./文件名/bin/activate
安装该环境的库:pip install
查看该环境所有的库:pip freeze
把输出保存到txt文件中:pip freeze>requirements
退出:deactivate
安装requirements:pip install -r requirements
3、设置pip引入国内源
国内一些源:
国内的一些代理源:
阿里云 :http://mirrors.aliyun.com/pypi/simple/
中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
豆瓣:http://pypi.douban.com/simple/
设置方法:
1.cd ~ &&mkdir .pip && cd .pip
2.touch pip.conf
3.
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
参考博客:https://www.jianshu.com/p/c0debdf9d629
http://baijiahao.baidu.com/s?id=1603890726494853371&wfr=spider&for=pc