This is the multi-page printable view of this section. Click here to print.
Python
Python notes for myself as I learn the language.
1 - venv
venv
Create a dir (and any subdirs) and place a pyvenv.cfg as well as a bin dir.
python -m venv PATH
For example:
python -m venv .venv
To activate the virtual environment:
source PATH/bin/activate
To deactivate the virtual environment:
deactivate
2 - Pytest
Pytest
To install:
pip install pytest
To execute:
pytest
Pytest will run the tests in any file prefixed with test_.
3 - Pyenv
How to install and configure Pyenv. This is a WIP.
Install pyenv:
brew update
brew install pyenv
Configure pyenv:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Install build deps of MacOS: brew install openssl readline sqlite3 xz zlib tcl-tk
List available versions: pyenv install -l
Install a version: pyenv install version
Set a global version to use: pyenv global version
There are three ways to set the python version to be used:
- 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