Useful tools for local development

Useful tools that can help you with developing Python Exercism code on your own machine.


Note

This is a collection of tools that are popular in our community. It is not intended to be prescriptive nor exhaustive. We think these tools do their job well, but there are most certainly other tools that are also good. If you have an editor, IDE, tool, or plugin recommendation, we encourage you to add it to this document on GitHub.



Before you start exploring, make sure that you have a recent version of Python installed. The Exercism platform currently supports Python 3.7 - 3.11.2 (exercises and tests) and Python 3.11.2 (tooling). For more information, please refer to Installing Python locally.


Virtual Environments

Python virtual environments offer lightweight runtime and package isolation. They can help to organize your projects by keeping the Python packages you install bundled together inside a particular environment directory. Different environments can hold different versions of the Python runtime together with any project or library dependencies. This helps avoid bugs and incompatibilities caused by upgrading a library for one project that "breaks" a dependency in a different one.

There are two major virtual environment tools in use today, the Python standard library venv and the third-party conda env, using the conda package manager and (usually) the Anaconda Python distribution. Both of are straightforward to use and/or install.

Additionally, PyEnv and virtualenvwrapper are tools that can help to manage multiple versions of Python and multiple Python environments on the same machine.


Creating a virtual environment with venv

To create a virtual environment using venv, cd to the directory you want to store your environments in. This should be a directory separate from the code for your project, and one you will not be checking into source control. Next, run the venv command with the name of a folder where you want to store this particular environment. Common convention is to call that folder <project-name-here>_venv:

Windows

PS C:\Users\foobar> py -m venv {name_of_virtualenv}

To activate the virtual environment, run the following command:

PS> .\{name_of_virtual_env}\Scripts\activate.bat
(venv) PS> _

Linux/MacOS

$ python3 -m venv {name_of_virtualenv}
created virtual environment ... in 8568ms

To activate the virtual environment, run the following command:

$ source {name_of_virtual_env}/bin/activate
(venv) $ _

Once a venv is activated, you can run pip commands for package installation "inside" the environment. Installed packages will be associated with the venvs version of Python, and located inside {name_of_virtual_env}/Lib.

Deactivating a virtual environment can be done by calling the deactivate script, located in the same directory as activate.


Creating a Virtual Environment using conda

The latest conda version can be installed via miniconda. This conda cheatsheet is very helpful, as are the conda docs.

Originally created as a Python package manager for the popular Anaconda distribution of "scientific Python", conda was later generalized and extended. Conda environments are similar to venvs, with the key difference being that conda can create virtual environments and install packages for many other programming languages in addition to Python.

Conda supported languages include R, JavaScript, Ruby, Fortran, C/C++, Scala, Java, and more. For a comparison of conda vs venv commands, see the conda command reference.


MacOS/Linux

To create a conda environment, type the following, replacing {name of environment} with your chosen name, and python={version} with your desired version of Python. This can be followed by any additional packages you wish to install inside the environment:

$ conda create --name {name of environment} python={version} "pytest>6.0" pylint
...

## Package Plan ##

  environment location: /usr/local/anaconda3/envs/test_env

  added / updated specs:
    - pylint
    - pytest[version='>6']
    - python=3.10


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    astroid-2.11.1             |  py310h2ec42d9_0         364 KB  conda-forge
    dill-0.3.4                 |     pyhd8ed1ab_0          62 KB  conda-forge
    lazy-object-proxy-1.7.1    |  py310he24745e_0          32 KB  conda-forge
    ....
    additional packages here
    ....
    ------------------------------------------------------------
                                           Total:        21.8 MB

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate test_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Windows

Creating a conda environment on Windows uses the same general commands as Linux/MacOS. However, it is recommended that you use either the Anaconda cmd or powershell prompts over adding conda to your path:

(base) PS C:\Users\foobar> conda create --name {name_of_environment} python={version} "pytest>6" pylint
...

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\ProgramData\Anaconda3\envs\test_env

  added / updated specs:
    - pylint
    - pytest[version='>6']
    - python=3.10


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    astroid-2.11.1             |  py310h5588dad_0         364 KB  conda-forge
    attrs-21.4.0               |     pyhd8ed1ab_0          49 KB  conda-forge
    bzip2-1.0.8                |       h8ffe710_4         149 KB  conda-forge
    ...
    additional packages here
    ...
    ------------------------------------------------------------
                                           Total:        37.5 MB

Proceed ([y]/n)? y
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate test_env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Virtual Environment wrapper

Documents and background: virtualenvwrapper.

The virtualenvwrapper package works on top of venv to manage all your virtual environments in one place. You can create, copy, delete and switch between environments with linux-like commands such as lsvirtualenv (to list envs) and mkvirtualenv (to make an env). It also allows you to add additional management tools using extensions. You can even create your own extensions to the tool using this tutorial.


PyEnv

pyenv is the Python fork of the popular rbenv/ruby-build tools modified for Python. It is essentially a set of scripts and shims that allow for setting Python versions on both a global and user-specific basis. It tries to adhere to the Unix tradition of a single-purpose, unobtrusive tool that does one thing well.

pyenv and the pyenv docs can be found on GitHub.



Editors and IDEs



Visual Studio Code

Visual studio code (VS Code) is a free code editor created by Microsoft. It includes great support for both virtual/conda environments, as well as docker (via the docker plug-in) and can be extended with many different plugins for testing, linting, formatting, and web development.

Python for VS Code

Extension-id: ms-python.python

Python Extension Header on VS Code

The Python extension from Microsoft is the official Microsoft Python extension to VS Code, and a highly recommended installation. It has a wide range of features, including environment management, test management, linting, and debugging. As of the latest release, installing the MS Python extension will also download pylance (a popular package for linting and validating Python code), and jupyter (for working with Jupyter Notebooks).

  • A setup tutorial is available here and the settings reference is very helpful.
  • Information on setting up Python versions/working with virtual environments can be found here.
  • Information on setting up and working with unittest and pytest in VS Code can be found here.

PyCharm

PyCharm is an IDE (Integrated Development Environment) built by JetBrains. It is purpose-built for Python and is popular among professionals . Like VS Code, it can be extended with various paid and unpaid plugins, themes, and formatters. The paid version also supports Django development, Docker development, and Database integration.

Pycharm and Pytest
  • Steps for setting up pytest with pycharm can be found here.
  • Pycharm defaults to using unittest, so you must have pytest installed into the environment you are using with pycharm (see the interpreter and environment documents above), and then point pycharm to it.
  • Running Tests directly from the GUI is really easy, but don't forget to take a good look at the underlying pytest parameters, so that it is set up to your liking.
  • General documentation for running tests and debugging in pycharm can be found here.
  • Additional debugging tools and guidance can be found here.

Spyder IDE

Spyder is a cross-platform free and open source Python IDE tailored for the scientific community. It is commonly included with the Anaconda distribution of Python, but can be installed by itself and used with any version of Python. We recommend a standalone installation to ensure maximum flexibility, and that there are no package conflicts.

Spyder fully supports venv and conda environments. It includes an integrated IPython interactive terminal, an interactive debugger, and rich support for in-editor graphing and data exploration. Additional code completion and linting are provided via kite. Integrations with Jupyter Notebooks and testing tools are provided via community-developed plugins. You can also write plugins of your own, using the Spyder API.


Emacs

Emacs is a free, open source, and highly customizable text editor written in Lisp. A great installation and setup guide is available at Real Python.

  • The Emacs Wiki also has a good guide to Python programming with Emacs.
  • Full Stack Python also collects some good information and links for getting started with Emacs.

Vim

Vim is a free and "improved" version of the Unix standard vi text editor. It is available on a wide variety of operating systems and Linux/Unix flavors. A great installation and setup guide is available at Real Python, and handy cheat sheets are available at vimsheet, glump, and rtorr.

Even if you decide editing Python code in vim is not for you, it is recommended that you familiarise with a basic set of commands. vim or vi is often a "base" or "default" text editor in Linux and Unix distributions and is the default editor for git commit messages (among other things) on those systems. Chances are good you will find yourself on a *nix system needing to edit a configuration file with only vi available, so knowing how to quit vim is (at the very least) good self defense.


Spacemacs

Spacemacs (github repo) is a free community-driven distribution of Emacs that combines functionality from both Emacs and Vim.

  • Official documentation can be found here
  • This guide at opensource gives a quick rundown of installation and configuration options.
  • The spacemacs python layer adds functionality for testing, linting, environment management, and code formatting.

Sublime text

Sublime text is a paid text editor for coding, made by Sublime HQ Pty Ltd. It is similar to VS Code and Atom, with many packages and plugins for customization. You can also develop plugins of your own for the editor using Python.