avatarFahmi Nurfikri

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1576

Abstract

="8a53"><pre>apt install -y make build-essential libssl-dev zlib1g-dev
> libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev
> libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
> git</pre></div><p id="cf20">After that, we will install the latest version on Pyenv. So, we will need to clone from the Pyenv repository.</p><div id="a958"><pre>git <span class="hljs-built_in">clone</span> https://github.com/pyenv/pyenv.git ~/.pyenv</pre></div><p id="7d94">And for the last step, we must add pyenv to our path so that the <code>pyenv</code> command is recognized globally.</p><div id="465b"><pre><span class="hljs-built_in">echo</span> <span class="hljs-string">'export PYENV_ROOT="HOME/.pyenv"'</span> &gt;&gt; ~/.bashrc <span class="hljs-built_in">echo</span> <span class="hljs-string">'export PATH="PYENV_ROOT/bin:PATH"'</span> &gt;&gt; ~/.bashrc <span class="hljs-built_in">echo</span> <span class="hljs-string">'eval "(pyenv init --path)"'</span> >> ~/.bashrc</pre></div><p id="566e">Finally, to start using pyenv, restart the shell by running:</p><div id="fe83"><pre><span class="hljs-built_in">exec</span> <span class="hljs-string">"<span class="hljs-variable">$SHELL</span>"</span></pre></div><h1 id="4891">Install Python</h1><p id="01af">To check whether pyenv is already installed on our machine, we can use this command.</p><div id="5ff4"><pre>pyenv --version</pre></div><p id="58be">In mine, the response is <code>pyenv 2.3.6–13-g4c261e6e</code>, if you do not see a result similar to this, then maybe t

Options

here is an error in your installation.</p><p id="7ae1">To see the available python version, you can use this command.</p><div id="07fb"><pre>pyenv install --list</pre></div><p id="bbe9">For example, I will install <code>python 3.9.15</code>. So the command will be like this.</p><div id="6d17"><pre>pyenv install 3.9.15</pre></div><p id="f151">Don’t worry if your terminal doesn’t return anything, the process takes a while. Maybe you can leave it for a while to make coffee or something.</p><p id="2a98">If the installation is already done, you can verify if the python version is already installed, you can use the:</p><div id="f768"><pre>pyenv versions</pre></div><p id="07de">And the result will look like this.</p><div id="a94e"><pre>* system (<span class="hljs-built_in">set</span> by /home/user/.pyenv/version) 3.9.15 </pre></div><p id="a2d1">The <code>*</code> is mean that <code>system</code> is the default python version. To set <code>python 3.9.15</code> as the default python, use the command:</p><div id="2dab"><pre>pyenv global 3.9.15</pre></div><p id="6f93">After that, check the python version.</p><div id="011d"><pre>python --version <span class="hljs-comment"># or python -V</span></pre></div><p id="3e9f">If the python version is 3.9.15 or whatever python version you install, then the python installation is a success. If you want to add another python version, you can just be using <code>pyenv install <version></code> and if you want to change the python version, you can just use <code>pyenv global <version></code>.</p></article></body>

How to Install Python using Pyenv on Ubuntu 20.04

Easy way to install and switch python version

Photo by Nubelson Fernandes on Unsplash

When it comes to python, did you ever find a problem installing or changing the python version? If yes, then we’re the same. I always got a problem when it comes to changing the python version and my only solution at that time is just uninstalling python and re-installing the version that I need.

After dealing with that problem for a long time, I finally found the tools to manage the python version, named Pyenv.

What is Pyenv?

Basically, Pyenv is a tool to simplify installation and version changing in python. It helps developers quickly install or change the python version without needing to change the whole system.

In this post, I will show you how to install pyenv and manage the python version.

Install Pyenv

To start the installation process, it’s a good idea to update the system packages. Open the terminal and write the command below.

apt update -y

After that, let’s install all Pyenv dependencies.

apt install -y make build-essential libssl-dev zlib1g-dev \
> libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev\
> libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl\
> git

After that, we will install the latest version on Pyenv. So, we will need to clone from the Pyenv repository.

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

And for the last step, we must add pyenv to our path so that the pyenv command is recognized globally.

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc

Finally, to start using pyenv, restart the shell by running:

exec "$SHELL"

Install Python

To check whether pyenv is already installed on our machine, we can use this command.

pyenv --version

In mine, the response is pyenv 2.3.6–13-g4c261e6e, if you do not see a result similar to this, then maybe there is an error in your installation.

To see the available python version, you can use this command.

pyenv install --list

For example, I will install python 3.9.15. So the command will be like this.

pyenv install 3.9.15

Don’t worry if your terminal doesn’t return anything, the process takes a while. Maybe you can leave it for a while to make coffee or something.

If the installation is already done, you can verify if the python version is already installed, you can use the:

pyenv versions

And the result will look like this.

* system (set by /home/user/.pyenv/version)
  3.9.15 

The * is mean that system is the default python version. To set python 3.9.15 as the default python, use the command:

pyenv global 3.9.15

After that, check the python version.

python --version  # or python -V

If the python version is 3.9.15 or whatever python version you install, then the python installation is a success. If you want to add another python version, you can just be using pyenv install <version> and if you want to change the python version, you can just use pyenv global <version>.

Python
Pyenv
Ubuntu
Programming
Recommended from ReadMedium