- pyenv github - python 版本管理器
Simple Python version management
- pipenv github - python 包管理器,更好用的 pip
Python Development Workflow for Humans. Pipenv is a tool that aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world.
pyenv
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
echo 'export PATH=~/.pyenv/bin:$PATH' >> ~/.zshrc
echo 'export PYENV_ROOT=~/.pyenv' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
pipenv
其中一条特性Automatically install required Pythons, if pyenv is available.
,配合pyenv
可以管理python
版本
pip3 install pipenv
使用
$ cd test
$ pipenv --two
Creating a virtualenv for this project…
$ pipenv shell
新建的虚拟环境存放在~/.local/share/virtualenvs/
下,想要删除这个环境,直接删除这个文件夹
常用命令
- pipenv install
- pipenv install bs4
- pipenv install django==1.11
- pipenv install –dev django
- pipenv install -r requirements.txt
- pipenv uninstall –all
- pipenv uninstall django==1.11
- pipenv graph
- pipenv update requests
- pipenv update
- pipenv shell
- pipenv –rm
- pipenv run pip install pip==18.0
- pipenv run pip uninstall pip==18.0
- pipenv run xxx.py
- pipenv lock
- exit
更换源
修改目录下的Pipfile
文件
阿里云:http://mirrors.aliyun.com/pypi/simple/
豆瓣:http://pypi.douban.com/simple/
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/
注意部分源访问存在问题
修改为使用清华大学源
$ pipenv install django==1.11
Installing django==1.11…
Adding django to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (f9ea0f)!
Installing dependencies from Pipfile.lock (f9ea0f)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 2/2 — 00:00:03
$ pipenv graph
Django==1.11
- pytz [required: Any, installed: 2019.2]
zsh 增加 virtualenv 支持
POWERLEVEL9K_PYTHON_ICON=$'\U1F40D'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(battery root_indicator dir dir_writable vcs virtualenv)
修改~/.oh-my-zsh/custom/themes/powerlevel10k/internal/p10k.zsh
prompt_virtualenv() {
[[ -n $VIRTUAL_ENV ]] || return
local msg=''
if [[ $POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION == true ]] && _p9k_python_version; then
msg="$_P9K_RETVAL "
fi
fullname=${${VIRTUAL_ENV:t}//\%/%%}
msg+=${fullname%%-*}
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" 'PYTHON_ICON' 0 '' "$msg"
}