Author note: VocĂȘ pode ler este artigo em PortuguĂȘs.
One of the first things we learn in Python is that there is more than one version of the same language working side by side. That can bring a few problems and the inevitable question: âWhich version should I choose?â. Todayâs tip teaches you a way to install and manage many Python versions on your machine using pyenv đ.
Amongst other things, the two best features of pyenv in my humble opinion are:
- install new Python versions easily;
- choose the global Python version.
To start youâll need to install pyenv, here Iâll demonstrate one of several installation methods, but in the projectâs readme file you can find other possibilities (and also operational system related details):
1
2
3
4
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ exec "$SHELL"
After these easy steps, other versions of Python are an install away:
class="highlight">1
$ pyenv install 3.6.4
When in doubt of which version you can install, just use the install flag -l that it lists all versions available:Se estiver em dĂșvida quais versĂ”es vocĂȘ pode instalar sĂł usar a flag -l do install que ele vai listar todas as disponĂveis:
class="highlight">1
$ pyenv install -l
Cool huh? Now you can install Python versions like crazy đ
And now, for the moment of truth, to configure the global version of Python, that is, to define which version of Python you will use when running Python, run the following command:
class="highlight">1
$ pyenv global 3.6.4
So regardless of where you navigate on your terminal, the Python version running will be 3.6.4. This command is handy if all of your projects are in the same version. Another nice feature of pyenv is to define a local Python, letâs say for instance that a given project only runs on Python 3.5.3, so you need to install that version (as you learned previously) and then go to that projectâs folder and use this command:
class="highlight">1
$ pyenv local 3.5.3
So whenever you enter the said project folder, pyenv will âactivateâ the correct Python for your project.
No more pain when dealing with Python versions! đ
Recent Articles
python How I removed the white background of my GIF blog signature using Python
A practical Python script with Pillow to remove a white GIF background frame by frame and wire a transparent signature into a Jekyll blog.
python Como removi o fundo branco da minha assinatura em GIF usando Python
Um script Python prĂĄtico com Pillow para remover o fundo branco de um GIF quadro por quadro e conectar uma assinatura transparente no blog Jekyll.
english git mv: rename files without the delete-and-add confusion
Use git mv to rename files so git tracks the change instead of showing a delete and a new file.