Software Description :
pyenv
, Is a particularly useful version of Python manager, a programmer can create a different directory, run different versions of Python in different directories separately and independently of each other, the installation package also affect each other. github project Address: https://github.com/yyuu/pyenv
pyenv-virtualenv
Is pyenv
a plugin (plugin), can be used to create a clean virtual environment based on different versions of Python. github project Address: https://github.com/yyuu/pyenv-virtualenv
Installation idea :
to install macOS package manager brew
, then brew
install pyenv
andpyenv-virtualenv
1. Install brew
Package Manager
brew full name Homebrew , is macOS a package manager under (macOS not have its own package manager), similar to CentOS belowyum
, Ubuntu underapt-get
command.
|
|
2. Use the brew
command to install pyenv
,pyenv-virtualenv
|
|
Will be installed autoconf
, pkg-config
, openssl
,readline
Installation process, we can see some Caveats (warning), we need to manually handle it.
First link readline to the system lib:
|
|
According Caveats then prompts modify environment variables, vim ~/.bash_profile
add the following content:
|
|
The above two settings to make pyenv
and pyenv-virtualenv
easier to use, can be used when the command completion.
Setting up the terminal closed, and then restart the terminal, it can take effect.
3. pyenv to use
**警告:
pyenv
安装Python是编译安装的,在使用之前要先安装zlib
和SQLite3
,要不然安装会报错。
安装zlib
和SQLite3
并链接:
|
|
然后根据Caveats的提示修改环境变量,vim ~/.bash_profile
添加下面内容:
|
|
用pyenv --help
可以查看pyenv
的使用帮助:
常用的几个pyenv命令:
pyenv install x.y.z
:安装 大专栏 macOS下Python多版本控制软件的安装:pyenv、pyenv-virtualenvPython,x.y.z
是Python的版本,如pyenv install 3.6.2
。
pyenv local x.y.z
:设置当前目录的Python版本为x.y.z
, 如pyenv local 3.6.2
。
pyenv versions
:查看安装的版本,前面带*
号的表示当前目录下正在使用的版本。系统自带的Python是System
,后安装的版本的都是版本号
。
下面给出使用的例子:
示例:
|
|
4. pyenv-virtualenv
的使用方法
pyenv-virtualenv是用来创建一个干净的虚拟Python环境的命令,通常在创建干净的新项目时候使用。使用方法如下:
1.创建虚拟环境–pyenv virtualenv 版本号 虚拟环境名
。
|
|
- 创建项目,让项目使用干净的Python3.6.2的虚拟环境:
|
|
We will find: As long as we enter the Learning-Python3
directory, it will automatically activate virtualenv, exit the Learning-Python3
directory, it will shut down virtualenv.
If you want to turn off automatic activation, you can run the command
pyenv deactivate
to re-enable it, runpyenv activate 虚拟环境名
.