- Check if venv module is installed
python -m venv --helpIf venv is not available, we might need to install python3-venv
- Create a Virtual Environment using venv
mkdir VENV
python -m venv VENV- Activate/Deactivate Environment
source VENV/bin/activatedeactivatepip install virtualenvOr
sudo dnf -y install python3-virtualenv #Based RHEL
sudo apt install python3-virtualenv #Debian/Ubuntuvirtualenv <env_name>virtualenv -p python3 <env_name>source <env_name>/bin/activatedeactivaterm -rf <env_name>-
Use one virtual environment per project.
-
Never commit the virtual environment directory to version control (add it to .gitignore).
-
Use
which pythonorwhere pythonto verify the active Python interpreter.
pyenv install --listpyenv install 3.9.6You can set a global Python version to be used in all shells by running
pyenv global <python_version>
pyenv global 3.9.6You can set a local Python version for a specific directory by running
pyenv local <python_version>
pyenv local 3.9.6pyenv versionsOnce you have installed multiple Python versions, you can switch between them using: pyenv global, pyenv local, or pyenv shell commands
pyenv global <python_version> #sets the global Python version.
pyenv local <python_version> #sets the local Python version for a specific directory.
pyenv shell <python_version> #sets the Python version for the current shell sessionpyenv virtualenv <python_version> <virtualenv_name>
pyenv virtualenv 3.12.0 myenvpyenv virtualenvspyenv activate myenvpyenv deactivate