We can install pyenv as follows:
curl https://pyenv.run | bashAfter installation, we will see instructions to add some lines to your .bashrc.
To enable pyenv, add the following to your .bashrc:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"Refer to this Japanese article.
- List the installable python versions:
pyenv install --list- Install the specific python version:
pyenv install <version>e.g.
pyenv install 3.12.12- Change which version use:
pyenv global 3.12.12or
pyenv local 3.12.12- List the changeable python versions:
pyenv versionsWe can create a local virtual environment with:
python3 -m venv .venvThe .venv directory will be created, and it is already listed in .gitignore to prevent
accidental commits.
To activate the virtual environment:
source .venv/bin/activateor
. .venv/bin/activateWe can activate the virtual environment in both PowerShell and cmd with:
.\.venv\Scripts\activateTo deactivate the virtual environment on any platform:
deactivatevenv needs to be deactivated and then needs to be activated again.
We can install the dependencies and your development source code in editable mode so that changes to the source code are immediately reflected without reinstalling. This is useful for development, as we will often update the source code.
To install in editable mode:
pip install -e .Currently, there is no configuration to build the Python module for deployment.
To install optional dependencies, use:
pip install -e .[dev]If we have several optional dependencies defined, for example:
[project.optional-dependencies]
dev = ["pytest"]
cli = ["rich", "click"]We can specify multiple keys in brackets:
pip install -e .[dev,cli]