抱歉,您的浏览器无法访问本站

本页面需要浏览器支持(启用)JavaScript


了解详情 >

blaire

👩🏻‍💻ブレア🥣

It needs to be used in both python2 and python3 environments, or different packages need to be installed in different projects.

we hope that the packages installed between different projects do not interfere with each other, and then you can configure the virtual environment of Python using pyenv.

installation pyenv

Official Pyenv Install

1
2
3
4
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
#export PYENV_VIRTUALENV_DISABLE_PROMPT=1

按照官方文档配置即可,mac zsh 用户,将 以上三句放入到 .zshrc 即可。

see available versions

1
pyenv install -l

install python in virtual env

install python 2.7.14

1
pyenv install 2.7.14

install python 3.6.3

1
pyenv install 3.6.3

solve macOS High Sierra: ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

1
2
3
4
5
6
7
8
9
10
11
# about zlib
export CFLAGS="-I$(xcrun --show-sdk-path)/usr/include"
# about readline
export CFLAGS="-I$(brew --prefix readline)/include $CFLAGS"
export LDFLAGS="-L$(brew --prefix readline)/lib $LDFLAGS"
# about openssl
export CFLAGS="-I$(brew --prefix openssl)/include $CFLAGS"
export LDFLAGS="-L$(brew --prefix openssl)/lib $LDFLAGS"
# about SQLite (maybe not necessary)
export CFLAGS="-I$(brew --prefix sqlite)/include $CFLAGS"
export LDFLAGS="-L$(brew --prefix sqlite)/lib $LDFLAGS"

Set or show the global Python version

1
$ pyenv global 3.6.3 or system

system stands for this mac

show list all Python versions available to pyenv

1
$ pyenv versions

create virtual env

create current 3.6.3 version python virtual env

1
$ pyenv virtualenv vpy3

vpy3 is this virtual env alias

pyenv activate & deactivate

1
$ pyenv activate vpy3

这是时候就可以开始pip安装依赖包了

1
2
3
4
5
6
7
8
9
10
11
12
➜ pyenv activate vpy3
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(vpy3)
# ~ [12:25:44]
➜ python -V
Python 3.6.3
(vpy3)
# ~ [12:25:49]
➜ pyenv deactivate vpy3
# ~ [12:25:57]
➜ python -V
Python 2.7.10

Comments