python 虚拟环境

传统 virtualenvwrapper

sudo apt install virtualenv
sudo apt install virtualenvwrapper
sudo find / -name 'virtualenvwrapper.sh'
mkdir ~/.virtualenvs  or mkdir ~/envs
export WROKON_HOME=~/.virtualenvs       or  envs

###iwnodws 设置的时候 要小写  workon_home 
source /usr/local/bin/virtualenvwrapper.sh  or  使用上马find找到的 virtualenvwrapper.sh
#### 可以在root 下 .bashrc 最后添加一句export WROKON_HOME=/home/dfk/.virtualenvs 把目录移到外面 方便pycharm导入
source ~/.bashrc

mkvirtualenv -p /usr/bin/python3 djangopy3

workon 

deactivate

pip freeze > rexx.txt 打印出所有包
pip install -i https://pypi.douban.com/simple -r rexx.txt 安装所有包

新奇 pipenv

新建一个准备当环境的文件夹pipenvtest,并cd进入该文件夹:
pipenv --three 会使用当前系统的Python3创建环境

pipenv --python 3.6 指定某一Python版本创建环境

pipenv shell 激活虚拟环境

pipenv --where 显示目录信息
/home/jiahuan/pipenvtest

pipenv --venv 显示虚拟环境信息
/home/jiahuan/.local/share/virtualenvs/pipenvtest-9KKRH3OW

pipenv --py 显示Python解释器信息
/home/jiahuan/.local/share/virtualenvs/pipenvtest-9KKRH3OW/bin/python

pipenv install requests 安装相关模块并加入到Pipfile

pipenv install django==1.11 安装固定版本模块并加入到Pipfile

pipenv graph 查看目前安装的库及其依赖

pipenv install 安装模块时有时候会很慢
可以设置国内源:Pipfile文件中[source]下面url属性,比如修改成:url = "https://pypi.tuna.tsinghua.edu.cn/simple"

ubuntu
升级python3.6
安装:

1、add-apt-repository ppa:jonathonf/python-3.6

2、apt-get update

3、apt-get install python3.6

配置只输入python3时就默认使用3.6版本:

1、update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1

2、update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2

3、update-alternatives --config python3

4、python3 -V

设置pip:

1、apt-get install python3-pip    # Python3

2、apt-get install python-pip     # Python2

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容