Skip to content

wk-tan/python-dev-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

Python Development Environment Setup

pyenv

pyenv is a simple Python version management.

  1. Ensure python command is OS default.
echo `python --version`; echo `python3 --version`
echo `which python`; echo `which python3`
  1. Install the latest version of pyenv in home folder.
cd ~
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
  1. Verify pyenv installation by checking its version and list installable python versions.
pyenv --version
pyenv install -l 
  1. Install Python build dependencies following this link.

  2. Install multiple versions of python and set one of them at global level.

pyenv install 3.8.13
pyenv install 3.9.13
pyenv install 3.10.5
pyenv global 3.9.13
pyenv versions
  1. Verify python 3.9.13 is set at global level.
echo `python --version`; echo `python3 --version`
echo `which python`; echo `which python3`
  1. Upgrade pip and list all pip installed packages.
pip install -U pip
pip list
  1. Install JupyterLab and multiple commonly used packages.
pip install jupyter jupyterlab black flake8 isort poetry-kernel

Poetry

Poetry is a tool for dependency management and packaging in Python.

  1. Install the latest version of poetry in home folder.
cd ~
curl -sSL https://install.python-poetry.org | python3 -
  1. List poetry config and set creation of virtual environment to be within a project folder.
poetry config --list
poetry config virtualenvs.in-project true

Continue from an existing project

  1. Clone a GitHub repository which is developed using different python version.
git clone git@github.com:{username}/{awesome_project}.git
cd {awesome_project}
pyenv local {python_version}
  1. Install the repository dependencies in .venv folder.
poetry install

Extras

Utilize Poetry kernel in JupyterLab

  1. Install ipykernel as a development dependency.
poetry install --dev ipykernel
  1. Choose Poetry as a running kernel.

Configure black, flake8 and isort in VS Code

  1. Set following key-value pairs in settings.json.
{
  "python.defaultInterpreterPath": "/home/waikiat/.pyenv/shims/python",
  "python.sortImports.path": "/home/waikiat/.pyenv/shims/isort",
  "python.sortImports.args": [
    "--profile=black",
  ],
  "python.formatting.blackPath": "/home/waikiat/.pyenv/shims/black",
  "python.linting.flake8Path": "/home/waikiat/.pyenv/shims/flake8"
}

About

A summarized walkthrough to setup Python development environment using pyenv and Poetry.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Contributors