python environments

python environments

  • Use pyenv to switch between Python versions.
  • Use venv for creating of virtual environments.
pyenv versions

pyenv version
python --version

# install a version
pyenv install 3.10

# select just for current shell session
pyenv shell <version>
# automatically select whenever you are in the current directory (or its subdirectories) 
pyenv local <version>
# select globally for your user account
pyenv global <version>

# uninstall
pyenv uninstall <versions>
  • Use venv for creating of virtual environments.
# create virtual environment name .venv
python -m venv .venv
# activate the virtual environment
source .venv/bin/activate
# install packages in .venv
pip install transformers flask
# save Dependencies
pip freeze > requirements.txt

# to re-create the environment
python -m venv newenv
source newenv/bin/activate
pip install -r requirements.txt

17. Sep 2024