# Switch Python versions

The procedures below explain how to switch Python versions by adding your custom environment in pip- and conda-based environments.

> **Note:**
> As a result, every time the notebook is started, `init.sh` will be executed and the custom configuration will be applied. Therefore, initializing this new environment may take longer than usual.

## Switch Python versions in pip-based environment

Procedure:

> **Tip:**
> In this procedure, a new virtual environment is assumed to be named as `customPyEnv311`. Adjust accordingly, whenever required.

1. Open the notebook where you want to customize your environment.

2. In the sidebar, select ![Attach](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/attach.svg) (Attached data).

3. Click Notebook files to expand the list and open `environment.yml`.

4. Edit the `environment.yml`  file as shown in the examples below:

```YAML
datalore-env-format-version: "0.2"
datalore-package-manager: "pip"
datalore-base-env: "customPyEnv311"
dependencies:
```

5. Configure the notebook to use the custom virtual environment based on your environment file:

1.  In the sidebar, select ![Environment](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/environment.svg) (Environment).

2. Click the Edit init.sh to install additional dependencies link.

3.

Add a command to build the virtual environment.

```SHELL
ENV_NAME=customPyEnv311
sudo apt-get update && sudo DEBCONF_NOWARNINGS=yes apt-get install -y python3.11 python3.11-venv
/usr/bin/python3.11 -m venv /opt/python/envs/$ENV_NAME
# The below packages are mandatory for the environment operation.
/opt/python/envs/$ENV_NAME/bin/python -m pip install ipykernel==5.5.3 ipython==7.31.1 ipython_genutils==0.2.0 jedi==0.17.2 aiohttp==3.8.3
# Any other library can be installed in the same way
/opt/python/envs/$ENV_NAME/bin/python -m pip install pandas>=1.5.3
```

6. Restart the machine to apply changes.

## Switch Python versions in conda-based environment

Procedure:

1. Open the notebook where you want to customize your environment.

2. In the sidebar, select ![Attach](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/attach.svg) (Attached data).

3. Click Notebook files to expand the list and open `environment.yml`.

4. Edit the `environment.yml`  file as shown in the examples below:

```YAML
datalore-env-format-version: "0.2"
datalore-package-manager: "conda"
datalore-base-env: "py39"
dependencies:
```

5. Create a new environment to specify the required Python version:

1. Under Notebook files, click the New file icon.

2. In the new file, add the content as shown in the example below.

```YAML
channels:
- conda-forge
- defaults
dependencies:
    - python=3.9.10
    - pyyaml
    - protobuf
    - python-logstash
    - wrapt
    - ipykernel
    - ipython_genutils
    - jupyter_client
    - jedi
```

6. Build a new virtual environment based on your custom environment file:

1.  In the sidebar, select ![Environment](https://resources.jetbrains.com.cn/help/img/datalore/2026.3/environment.svg) (Environment).

2. Click the Edit init.sh to install additional dependencies link.

3. Add a command to build the virtual environment.

> **Warning:**
> Make sure you refer to the environment file you created in the previous step.

```SHELL
/opt/anaconda3/bin/conda env create --name py39 --file py39env.yml
```

7. Restart the machine to apply changes.

