If you had ever wished to assist to an application that makes use of several different Python versions but weren't sure whether you would quickly test them all? Do you ever want to know about the most recent Python releases? Perhaps you want to test out these new features but are concerned that doing so would ruin your programming environment. Fortunately, if you use pyenv, handling various Python editions is not necessarily challenging.
A fantastic tool for handling many Python versions is pyenv. Especially if you currently have Python set up on your computer, installing pyenv will allow you to quickly experiment with new language features or give support to a project using a different version of Python. A handy approach to install beta versions of Python such that you could test those for issues is to employ pyenv.
Why not Utilize the Python System?
The Python which goes pre-installed on the operating system is known as "System Python." When simply type python in the console on either a Mac or Linux computer, you automatically receive a lovely Python REPL.
You must type sudo pip install to add a module to the Python system. Since you installed the Python module worldwide, it will be difficult for a different user to download a little earlier version of the module in the future. Different variations of a single package issues frequently sneak up onto you and catch you off guard. One typical way this issue manifests itself is when a well-known and reliable software starts acting strangely on your system.
Manager of Packages
Package managers are the natural place to turn after that. Typical possibilities for the following step include programmes like apt, yum, brew, or port. After all, this is how the majority of software are installed on your system. Unfortunately, utilising a package management will cause some of the same issues. Once more, these system-level programmes contaminate your development environment and find it difficult to sharing a workspaces with one another.
Package managers often put their packages into the global system area rather than the user space by default. Again, you are at the responsibility of whatever Python version may very well be present. While some repositories may provide you a wider variety, by default you're viewing whatever Python version your specific vendor is using at the time.
Choosing a Python Version
How precisely the python command is handled and also what instructions may be used to change it are two of the most perplexing aspects of pyenv. There are three ways to change the version of Python you're using, as stated in the instructions. What connection does each of these directives have to the others, finally? The resolving order is somewhat similar to this:
Apply pyenv Installer
After installing all the prerequisites as outlined in the aforementioned section, you may immediately perform the following instruction to activate Pyenv.$ curl
https://pyenv.run | bash
Do not even neglect to include the following words in the.bashrc file after that.
export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"
The terminal process should then be restarted for it to take effect.
Control various Python Versions
Employing pyenv, you may control the editions in your operating system and install a particular version of Python, similar to any other package manager. Let's examine each one in turn.
Install pyenv in Python
To download Python, we should use installation command and then the unique identifier. Before then you may perform the following command to view every Python version that is presently available.
$ pyenv install --list $ pyenv install --list Available versions: 2.1.8 2.2.8 2.3.3 2.4.0 2.4.5 2.4.6 2.4.7 2.4.8 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.5 2.6.6 2.6.8 2.6.8 2.6.9 2.7.0 2.7.01 2.7.1 2.7.2 2.7.3 2.7.5 2.7.5 2.7.6 2.7.7 2.7.81 2.7.19 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.15 2.7.16 2.7.17 2.7.18 3.0.01 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 ... ... ….. # and so on # more
Utilizing pyenv to Control Default Python
You may choose and modify the default versions of Python utilizing pyenv instructions after installing and maintaining the necessary Python versions on your pyenv list. Use the command below to view a variety of technological Python versions.
$ pyenv versions * system (set by /home/kalan/.pyenv/version) 2.8.0 3.7.6
Then, you can easily execute the following instructions to maintain Python 3.7. 6 as the system default.
$ pyenv global 3.7.6
$ python -V Python 3.7.6
The pyenv listing also shows the same thing.$ pyenv versions
system (set by /home/kalan/.pyenv/version) 2.8.0 * 3.7.6
Therefore, the Python version indicated by the * is the one that is installed and set as the standard by Pyenv global.
We have covered using Pyenv to manage several Python versions. We'll cover managing several Python versions simultaneously as well as managing numerous Python versions in various virtual environments in the following post.