Guide on Building a Modern Python Development Environment in 2024

Python Interpreter

Regardless of whether we are using Windows or any UNIX-like OS, directly installing Python or using the preinstalled version is not advisable. This approach poses two main problems:

Background

Several solutions have been introduced in recent years to address these issues:

The difference between Anaconda, Miniconda, Miniforge, Mambaforge, Conda, Mamba and Micromamba

TL; DR: Stick to Miniforge distribution

It seems that using Conda as our package and environment manager is the way to go, but there are many related tools and distributions that can cause confusion. Let's break it down.

Anaconda Inc. created a tool called Conda, and that's where it all began. They bundled a large set of useful packages with Python and Conda into an distribution called the Anaconda Distribution. However, because it was large and included many domain specific packages, they also released a smaller version called Miniconda. Miniconda contains just Python and the minimal set of packages necessary to run Conda (since Conda itself is written in Python).

As time passed, the Conda user community grew dissatisfied with the slow update cycle of Anaconda's default package channels. They created a faster, community-driven channel called "conda-forge" and bundled it into a new distribution named Miniforge.

However, as conda-forge grew, using Conda for package installations became slower. To address this, parts of Conda were rewritten in C++ to improve performance, resulting in a frontend tool (Mamba) and a backend solver library (Limamba).

Further development led to the creation of Micromamba, which fully rewrote Conda and changed its command-line interface. Micromamba doesn't rely on Python but does have a different CLI interface compared to Conda (and Mamba).

Based on Mamba (not Micromamba), the community created a new distribution called Mambaforge. However, the only difference between Miniforge and Mambaforge was the use of Mamba instead of Conda. As a result, they decided to merge both by replacing Conda with Mamba in Miniforge, making "Mambaforge" obsolete.

In the year of 2025, Mambaforge (and Miniforge's PyPy version) is finally obsoleted.

In conclusion:

Install

We can install Miniforge either by downloading it directly from its official source.

For detailed installation instructions, refer to the official Miniforge documentation or manual.

Miniforge Install Guide

Miniforge Download Offcial

Miniforge Download Mainland China Mirror

Config

Edit ~/.condarc

# libmamba is the default solver in the latest installation of Miniforge and Miniconda. Keep it for reference.
# solver: libmamba

# Enable strict channel priority for faster and more robust solving.
channel_priority: strict

# Show channel URLs for easier debugging
show_channel_urls: true

# Channel configuration
# !! DO NOT use "defaults" with "conda-forge" !!
# If still need to use, please set "channel_priority" to "strict" as above.
# See: 
# 1. https://mamba.readthedocs.io/en/latest/user_guide/troubleshooting.html#using-the-defaults-channels
# 2. https://conda-forge.org/docs/user/transitioning_from_defaults/#a-historical-note
# 3. https://conda-forge.org/docs/user/tipsandtricks/#using-multiple-channels
# 4. https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html#fresh-install-recommended
channels:
  - conda-forge

For mainland China readers, add these:

# Uncomment if using Anaconda or Miniconda
#default_channels:
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
# pytorch channel is deprecated, use conda-forge (or pip / wheel) instead:  
#  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  intel: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  nvidia: https://mirrors.sustech.edu.cn/anaconda-extra/cloud/

Also, mainland China readers can add pip mirror by executing:

pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

This command sets the mirror globally by placing a dotfile in the home directory, so you only need to run it once.

Basic Usage

Read the friendly manuals.

Conda User Guide

Mamba User Guide

Basiclly, we can replace every conda command with mamba, and mamba has an additional command called repoquery.

On Windows:

Detailed description and possible solution

NOTICE: Never install or update anything in the base environment. If we want to update, reinstall the latest version instead. Always create a new environment rather than using the base environment directly.

Advanced Usage: Switch Different Implmentation of MPI, OpenMP and BLAS

conda install "mpich=x.y.z=external_*"
conda install "openmpi=x.y.z=external_*"

Unlike MPI, manually setting OpenMP and BLAS is unnecessary in most of the time.

You can only use one of them!

conda install _openmp_mutex=*=*_llvm
conda install _openmp_mutex=*=*_gnu

You can only use one of them!

conda install "libblas=*=*mkl"
conda install "libblas=*=*openblas"
conda install "libblas=*=*blis"
conda install "libblas=*=*accelerate"
conda install "libblas=*=*netlib"

See more detail:

Using external MPI libraries

Switching OpenMP implementation

Switching BLAS implementation

Basic Environment for Data Science

Readers should not use this directly but do some search on every package and use it as a reference.

PyTorch 2.5.1 with CUDA 12.4.1 (Obsolete!)

conda install python=3.12 ruff jupyter tqdm matplotlib seaborn pandas pyarrow scikit-learn scikit-image scikit-learn-intelex pytorch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 pytorch-cuda=12.4 conda-forge::cuda-version=12.4 cuda opt_einsum safetensors librosa -c pytorch -c nvidia/label/cuda-12.4.1

Latest PyTorch with CUDA 12.6.3

conda install python=3.12 ruff jupyter tqdm matplotlib seaborn pandas pyarrow scikit-learn scikit-image scikit-learn-intelex cuda-version=12.6.3 cuda opt_einsum safetensors librosa -c nvidia/label/cuda-12.6.3
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

Tooling

Despite Python's simplicity, its tooling can be quite complex. The writer apologizes for the brief explanations; providing a detailed comparison is beyond the scope here. The recommendations are based on personal experience, and the lists are unordered. The criteria for selection are a GitHub star count of over 2,000 and a certain level of maturity.

Formatter

Linter

Currently, for both formatting and linting, Ruff is the best choice. It's fast, accurate, and outperforms other tools. Check it out!

Ruff Offcial Website

Readers are recommended to install the latest version of Ruff in each environment.

(Static) Type checker

Unfortunately, Ruff does not handle type checking. For our purposes, we need static type checkers. Here are some options:

In most cases, readers don't need to install Pyright manually, as Pylance is included with VSCode's Python extension.

And one more thing writer would like to mention about is that, pyright has history of shame and caused a community fork. See:

basedpyright Offcial Website

Unfriendly Comment Made by pyright's Maintainer

Project Manager

The writer lacks in depth knowledge of this section. Only a list can be provided.

DO NOT USE Poetry! It uses a non-standard implementations of key features: private field in pyproject.toml

Editor / IDE

Currently there are various choices:

Today, we'll discuss VSCode. PyCharm is user-friendly and requires minimal configuration. Emacs and Vim are versatile but require more setup and personal adjustment, so I won't cover them here. Spyder, which emulates RStudio, is worth trying if you come from an R background. However, it lacks some features compared to VSCode and PyCharm, which I strongly recommend instead. IDLE, bundled with Python, offers basic functionality and is less convenient compared to other options.

VSCode vs PyCharm

Before diving into VSCode, it's important to understand when to choose PyCharm or VSCode:

In September 2024, a well-customized VSCode can match or even surpass PyCharm in certain areas. Other editors, except Vim and Emacs, generally fall short.

For Beginners: Either PyCharm or VSCode is acceptable.

For Backend Web Development: PyCharm Professional is the better choice. It offers strong out-of-the-box support for popular web frameworks and useful features like database integration and regex validation, which are essential for backend development.

For Deep Learning: VSCode is preferred. It excels in remote development, whereas PyCharm tends to be more "local" and less suited for remote tasks. PyCharm requires manual Jupyter kernel startup on the remote side, which is less convenient. VSCode handles these aspects automatically.

For Hobby Projects: The writer's choice is VSCode. It has smaller memory footprints. Additionally, PyCharm's auto-completion can be ineffective with newer or less common code, which can be distracting and interrupt your workflow. While you can disable this feature, toggling it manually is cumbersome.

VSCode Extension and Config

For basic Python development, consider the following extensions:

For deep learning development:

For data analysis:

For remote development:

Some additional useful extensions:

By default, VSCode is comparable to normal editors but requires extensive configuration to reach its full potential. Let's dive into setting it up.

To configure VSCode, open settings.json and add the following lines based on your needs. Explore every option to tailor VSCode to your preferences. Note that some settings may be specific to Windows.

NOTICE: Some configuration settings may be specific to Windows!

    "telemetry.telemetryLevel": "off",                          // stop sending info to M$
    "files.autoSave": "afterDelay",                             // auto save after delay
    "editor.minimap.enabled": false,                            // disable minimap, writer believe it's useless
//    "editor.formatOnType": true,                                // format on type
//    "editor.formatOnSave": true,                                // format on save
    "editor.codeActionsOnSave": {                               // sort imports
        "source.organizeImports": "always",
    },
    "editor.cursorStyle": "underline",                          // my favorite cursor
    "editor.cursorSmoothCaretAnimation": "on",                  // move cursor smoothly
    "editor.cursorBlinking": "phase",                           // blinking cursor in phase
    "editor.smoothScrolling": true,                             // smooth scrolling
    "terminal.integrated.cursorStyle": "underline",             // terminal cursor style, VSCode seperates this from editor
    "terminal.integrated.cursorBlinking": true,                 // why not blinking
    "terminal.integrated.cursorStyleInactive": "block",         // when inactive, show as block
    "terminal.integrated.enableImages": true,                   // show image in terminal, have not tried
    "terminal.integrated.suggest.enabled": true,                // Intellisence for the terminal, wow!
    "terminal.integrated.defaultProfile.windows": "PowerShell", // I'm using Windows with pwsh now.
    "terminal.integrated.smoothScrolling": true,                // smooth scrolling
    "debug.showVariableTypes": true,                            // show var types when debuging
    "[python]": {                                               // specify Python's default formatter
        "editor.defaultFormatter": "charliermarsh.ruff",
    },
    "python.analysis.typeCheckingMode": "standard",             // enable type checking
    "python.analysis.inlayHints.variableTypes": true,           // enable inlay var type hints
    "python.analysis.inlayHints.callArgumentNames": "all",      // enable inlay arg name hints
    "python.analysis.inlayHints.functionReturnTypes": true,     // enable inlay ret type hints
    "python.analysis.autoImportCompletions": true,              // enable import completion
    "python.analysis.inlayHints.pytestParameters": true,        // enable inlay pytest param hints
    "python.terminal.activateEnvInCurrentTerminal": true,       // auto activate env in terminal 
//    "python.terminal.launchArgs": [                             // using IPython as default running, provides better output. However reader needs to manually install it in using environment.
//        "-m",
//        "IPython",
//       "--no-autoindent",
//    ],
    "notebook.lineNumbers": "on",                               // show line num in notebook
    "notebook.formatOnCellExecution": true,                     // format on cell execution
    "notebook.formatOnSave.enabled": true,                      // format on save
    "notebook.variablesView": true,                             // better var view
    "notebook.consolidatedRunButton": true,                     // show more options
    "notebook.experimental.remoteSave": true,                   // remote save tweak, esp. for slow network
    "notebook.outline.showCodeCells": true,                     // show code block in outline
//    "jupyter.widgetScriptSources": [                            // allow ipython widgets from 3rd parties, might cause security problems
//        "jsdelivr.com",
//        "unpkg.com"
//    ],
    "dataWrangler.experiments.fastCsvParsing": true,            // fast csv parsing. Requires the pyarrow package and pandas>=1.4.0.
    "path-intellisense.showHiddenFiles": true,                  // show hidden files when do path completion

Create .vscode/launch.json and paste the following configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Module",
            "type": "debugpy",
            "request": "launch",
            "module": "${command:extension.commandvariable.file.relativeFileDotsNoExtension}",
        }
    ]
}

The writer believes these are the relatively best extensions for Python development, and additional extensions are rarely necessary. If you find any that you think should be included, please contact me via email.

External Resource

VSCode Cheatsheet for Windows

VSCode Cheatsheet for macOS

VSCode Cheatsheet for Linux

PyCharm Cheatsheet for Windows and Linux

PyCharm Cheatsheet for macOS

Best Python Tutorial

Modern Good Practices for Python Development by Stuart Ellis



You've reached the end of this page. And you may Go to index or visit my friends.
About me and contacts
Except where otherwise noted, this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License