Installing different versions of Python on Linux using pyenv
Peace be upon you, and may the mercy and blessings of Allah be upon you. Hello Linux users, this time we will talk about tools that will help you if you want to use different versions of Python on your VM.Tool name Pienfu.
I personally only use this to help decompile or run bytecode scripts in Python. Yes, it is because each version of Python has different bytecodes :v.
>Installation
Clone the repository Pienfu and try to compile
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ cd ~/.pyenv && src/configure && make -C src
If you get any errors during compilation, just leave them alone. After that, you need to define environment variables for pyenv and install autocomplete. The code below applies to Un*x shells.
1. For bash
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile $ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
2.For Ubuntu desktop
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc $ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
3.For Zsh
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc $ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc $ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
4. For fish shells
$ set -Ux PYENV_ROOT $HOME/.pyenv
$ set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
$ echo -e '\n\n# pyenv init\nif command -v pyenv 1>/dev/null 2>&1\n pyenv init - | source\nend' >> ~/.config/fish/config.fish
Then restart your shell and make the changes. Now you can enter it. pyenv help
to see what we can do.
> How to use
use command pyenv install PYTHON.VERSION
Install the version of Python you want to install. example :
$ pyenv install 3.8.8
If you have installed Python version 3.8.8 and want to use that version of Python, enter the following command: pyenv global PYTHON.VERSION
. example :
$ pyenv global 3.8.8
You can check if your Python version has changed by typing:
$ python --version
Yes, that's it. Sorry if the words are wrong. Wasalamualaikum wr wb.