This guide takes for granted that pyenv has already been installed on your system. In this is not the case, ask an admin to refer to the pyenv guide.
These instructions are meant to be copy-pasted: variables introduced by the symbol <> are those that might change from one system to another, so be carefull if you are moving to another platform or have different configurations.
As a general guideline, we suppose that you are going to download only one python version but you might have more virtual environments. For these reason, all the commands, except the 5th point, must be run once. When you want to create a virtual enviroment, simply run the 5th point with a different virtualenv name.
# copy paste
git clone https://github.com/pyenv/pyenv.git ~/.pyenvThe following commands must be run only once per user.
Variables:
<~/.bashrc>: could be~/.bashrc,~/.zshrc, ...<~/.profile>: could be~/.profile,~/.bash_profile,~/.zsh_profile, ...
Commands to run:
# copy paste
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc && \
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc && \
echo 'eval "$(pyenv init -)"' >> ~/.bashrc# copy paste
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile && \
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile && \
echo 'eval "$(pyenv init -)"' >> ~/.profileRestart the shell:
# copy paste
source ~/.bashrc`The following commands must be run only once per user.
Variables:
<3.10.13>: any python version that you want
# copy paste
pyenv install 3.10.13We are going to locate a directory in which the command python returns the selected (downloaded) python version.
Variables:
<~/.python_versions>: any path in your$HOME<3.10.13>: any python version
Create a directory for that version
# copy paste
mkdir -p ~/.python_versions/3.10.13Use the directory to handle the python version
# copy paste
cd ~/.python_versions/3.10.13 && \
pyenv local 3.10.13Variables:
<venv_name>: any name
# copy paste
cd ~/.python_versions/3.10.13 && \
python -m venv venv_nameWhenever you want to use your virtualenv, run:
# copy paste
source ~/.python_versions/3.10.13/venv_name/bin/activate