What is pyenv?
- Want to have multiple python version ( 2.2.x, 2.3.x, 3.5.x, 3.5.x, etc) without messing with your laptop? Manage virtual env easily? Pyenv is your tool.
Installing and configuring pyenv
Some basic commands
pyenv python version control commands
-
pyenv install 3.6.0
- installs python 3.6.0 in pyenv -
pyenv install --list
orpyenv install --list | grep 3.6
view all python version3.6.x
that you can install -
pyenv global 3.6.0
- activates/enables 3.6.0 version of python -
python -V
orpyenv version -V
to view enabled python -
pyenv versions
- list all the python available in pyenv -
pyenv global system
- will undo the activated python and switch to the python install in your machine/system -
pyenv local 2.7.18
- will create a .python-version file. We use this command to define folder/project specific python. Basically if you are in this folder,python
command will be resolved topython 2.7.18
. You can also verify it bypyenv versions
- We can set python version by 3 ways
pyenv shell 3.8
,pyenv local 2.7.18
andpyenv global 3.5.9
pyenv virtualenv commands
-
pyenv virtualenv <python_version> <env_name>
- egpyenv virtualenv 3.5.9 my_env
- will creates a python env withmy_env
name - activate this newly created env -
pyenv activate my_env
- if you want to automatically activate this env after navigating to a project folder if do
pyenv virtualenv 3.5.9 my_env
>navigate to project
>pyenv local my_env
> will create.python-version
file with contentmy_env
so thatpyenv-virtualenv
plugin will know that you have already an env for this folder and activates this. Navigating out of this folder will deactivate the env - It also supports multiple env at once.
pyenv local env1 env2
- command will try to be resolved in env2 if failed then it will use env2
conclusion
- You have multiple python versions
- No need to activate env for projects manually
Top comments (0)