Skip to content

Latest commit

 

History

History
141 lines (93 loc) · 2.24 KB

File metadata and controls

141 lines (93 loc) · 2.24 KB

Python development

pyenv

Linux

We can install pyenv as follows:

curl https://pyenv.run | bash

After 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 -)"

Windows

Refer to this Japanese article.

Install python via pyenv

  • 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.12

or

pyenv local 3.12.12
  • List the changeable python versions:
pyenv versions

venv

We can create a local virtual environment with:

python3 -m venv .venv

The .venv directory will be created, and it is already listed in .gitignore to prevent accidental commits.

To activate the virtual environment:

Linux

source .venv/bin/activate

or

. .venv/bin/activate

Windows

We can activate the virtual environment in both PowerShell and cmd with:

.\.venv\Scripts\activate

To deactivate the virtual environment on any platform:

deactivate

If python version is changed

venv needs to be deactivated and then needs to be activated again.

Install a project in editable mode

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]