Skip to content
On this page

Building a Python Environment

This guide covers configuring Python environments in envd. If you’re new to envd please read our Tutorial and build configuration guides first.

Let's begin 🐍!

Specifying Python

The default language in envd is Python, thus there is no need to specify language. Or you can use base function to specify.

python
def build():
    base(os="ubuntu20.04", language="python")

The default version of python in envd is 3.9 (the latest patch version can be refered here). If you need to specify a particular version, just assign language to a string like pythonX.Y.Z:

python
def build():
    base(os="ubuntu20.04", language="python3.11")

WARNING

Python2 is not supported in envd.

Conda packages

You can install conda packages with install.conda_packages function. The following example installs numpy and scipy:

python
def build():
    base(os="ubuntu20.04", language="python")
    install.conda_packages(name = [
        "numpy",
        "scipy",
    ])

PyPI packages

You can install Python packages from PyPI with install.python_packages function. The following example installs scikit-learn and matplotlib:

python
def build():
    base(os="ubuntu20.04", language="python")
    install.python_packages(name = [
        "scikit-learn",
        "matplotlib",
    ])

envd uses system-wide pip to install Python packages in the previous example.

If conda is enabled, you can also install Python packages from PyPI with install.python_packags function. The following example installs numpy and scipy with conda, and installs scikit-learn and matplotlib with pip:

python
def build():
    base(os="ubuntu20.04", language="python")
    install.conda_packages(name = [
        "numpy",
        "scipy",
    ])
    install.python_packages(name = [
        "scikit-learn",
        "matplotlib",
    ])

envd uses pip in the current conda environment to install the packages in this example.

Specifying shell program

You can specify shell program used in the environment with shell function. The following example uses zsh:

python
def build():
    base(os="ubuntu20.04", language="python")
    shell("zsh")

Specifying VSCode extensions

You can specify VSCode extensions with install.vscode_extensions function. The following example installs ms-python.python[1]:

python
def build():
    base(os="ubuntu20.04", language="python")
    install.vscode_extensions(["ms-python.python"])

Setting up the Jupyter notebook

You can set up the Jupyter notebook with config.jupyter function. The following example sets up a Jupyter notebook:

python
def build():
    base(os="ubuntu20.04", language="python")
    # Use `config.jupyter()` 
    # if you do not need to set up password.
    config.jupyter(token="password")

jupyter

Setting up PyPI index mirror

Mirroring or caching of PyPI can be used to speed up local package installation, allow offline work, handle corporate firewalls or just plain Internet flakiness.

PyPI index mirror can be set with config.pip_index(url="<index>", extra_url=<extra>):

python
config.pip_index(url="https://pypi.tuna.tsinghua.edu.cn/simple")

  1. open-vsx is used instead of Microsoft VSCode Marketplace due to licensing issues. ↩︎

Released under the Apache-2.0 License. Built with VitePress.