likes
comments
collection
share

mac 安装virtualenv以及virtualenvwrapper

作者站长头像
站长
· 阅读数 4

遇到的问题太多了,记录一下怕以后自己找不到

安装virtualenv

首先是安装,在安装包的时候加一个国内源,下载速度会快一些 pip3.8是我自己安装的python版本号,mac自带python2.7的版本,如果要安装在Py2下的话使用pip命令就可以了

sudo pip3.8 install https://pypi.tuna.tsinghua.edu.cn/simple virtualenv

安装报错 Cannot unpack file /private/tmp/pip-unpack-bshxfv94/simple.html

报错信息如下

Cannot unpack file /private/tmp/pip-unpack-bshxfv94/simple.html (downloaded from /private/tmp/pip-req-build-qahlu0if, content-type: text/html); cannot detect archive format

ERROR: Cannot determine archive format of /private/tmp/pip-req-build-qahlu0if

解决方法 修改一下安装命令 增加**--trusted-host**

sudo pip3.8 install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn virtualenv

安装virtualenvwrapper

先在user里创建一个文件夹,存放环境

cd ~
mkdir .virtualenvs

跟刚才一样的命令 修改一下包名

sudo pip3.8 install https://pypi.tuna.tsinghua.edu.cn/simple virtualenvwrapper

配置virtualenvwrapper环境

先查找目前virtualenvwrapper的安装位置,把这个地址复制出来

which virtualenvwrapper.sh

然后进入.zshrc或者是.bash_profile

vim ~/.zshrc

添加以下内容

VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export WORKON_HOME=/Users/xxx/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
  • VIRTUALENVWRAPPER_PYTHON python的位置,可以使用which python3获得
  • WORKON_HOME虚拟环境的存放地址,就是我们第一步创建的地址
  • 第三行是加载命令,路径是which virtualenvwrapper.sh返回的 修改完成,保存文件之后重新加载配置文件
source ~/.zshrc

然后执行mkvirtualenv只要不是提示command not found就是安装成功了

转载自:https://juejin.cn/post/7026273769035399181
评论
请登录