Install, view, update, and uninstall Python libraries in a DSW instance using pip in Terminal. DSW persists all changes to the instance disk, so installed libraries survive restarts.
Which installation method should you use?
| Method | Where to run | Persistence | Best for |
|---|---|---|---|
pip install in Terminal | Terminal | Permanent (survives restarts) | Standard installs |
!pip install in a notebook cell | Jupyter Notebook | Permanent | When Terminal and notebook use different environments |
Install libraries
DSW supports multiple Python environments. pip installs into Python 3 by default. To install into a different environment, activate it first.
# Install in Python 3 (default)
pip install <yourLibraryName>
# Install in Python 2
source activate python2
pip install <yourLibraryName>
# Install in TensorFlow 2.0
source activate tf2
pip install <yourLibraryName>Replace <yourLibraryName> with the library name. For example: pip install bottle.
If a newly installed library cannot be imported, restart the Jupyter kernel. If the error persists, Terminal and the notebook may be using different Python environments — see Why does import fail after installing a library with pip?.
To install from a Jupyter Notebook cell, prefix the command with !:
!pip install bottleWhy the environment matters
Terminal and Jupyter Notebook may use different Python environments. If you install a library in Terminal but cannot import it in a notebook, run which python in Terminal and !which python in a notebook cell to compare. If the paths differ, install the library from within the notebook cell directly using !pip install.

View installed libraries
pip listUninstall libraries
pip uninstall <yourLibraryName>Replace <yourLibraryName> with the library name.
Only user-installed libraries can be uninstalled. Pre-installed system libraries cannot be removed.
Update libraries
To update a library to a specific version:
pip install --upgrade numpy==<versionNumber>Replace <versionNumber> with the target version.
Manage pip mirrors
View the current pip mirror
pip config listThe global.index-url value shows the active mirror URL. Sample output:
global.index-url='https://mirrors.aliyun.com/pypi/simple/'
global.trusted-host='mirrors.aliyun.com'
install.trusted-host='mirrors.aliyun.com'Use a different mirror for a single installation
Pass -i to override the mirror for one installation:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <yourLibraryName>
# If an SSL authentication error occurs, add --trusted-host:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn <yourLibraryName>Change the global pip mirror
Edit ~/.config/pip/pip.conf:
vim ~/.config/pip/pip.confTo use the Tsinghua University mirror, set index-url and trusted-host:
[global]
trusted-host=pypi.tuna.tsinghua.edu.cn
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=pypi.tuna.tsinghua.edu.cnFAQ
Will pip-installed packages be lost after an instance restart?
No. DSW preserves all instance disk data — including environments in /mnt/workspace and /root — when the instance uses a cloud disk as its system disk. Installed packages remain available after a restart.
Exception: Permanently deleting the instance erases all data.
Why does import fail after installing a library with pip?
Restart the Jupyter kernel first. If the error persists, Terminal and the notebook are likely using different Python environments. Run which python in Terminal and !which python in a notebook cell to confirm. If the paths differ, install the library directly from within the notebook:
!pip install <yourLibraryName>Alternatively, activate the correct environment in Terminal before installing:
# Install in Python 2
source activate python2
pip install --user <yourLibraryName>
# Install in TensorFlow 2.0
source activate tf2
pip install --user <yourLibraryName>How do I resolve dependency conflicts or version errors during pip install?
Try the following steps in order:
Switch the DSW image (recommended). Stop the instance and create a new one with an image that meets the library's requirements. For example, if a package fails on the PyTorch 2.1 image, try PyTorch 2.3 or a ModelScope series image, which often offer better compatibility.
Install a specific version. Check the library's documentation for a version compatible with the environment's Python and CUDA versions:
pip install package_name==x.y.zTry a different pip mirror. Network issues with the default mirror can cause failures:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <yourLibraryName>
How do I fix a "CUDA driver version is too low" error?
Do not attempt to upgrade the NVIDIA driver or CUDA Toolkit manually. The driver and CUDA versions in a DSW instance are pre-configured and cannot be changed — manual modification will corrupt the instance and cause data loss.
The correct fix: stop the current instance and create a new one using an official DSW image with the required CUDA version. The image tag indicates the CUDA version — for example, modelscope:1.9.4-pytorch2.0.1tensorflow2.13.0-gpu-py38-cu118-ubuntu20.04 includes CUDA 11.8 (cu118).
What do I do when pip install hangs or times out?
This is almost always a network issue. Work through the following steps:
Step 1: Check network connectivity
ping www.aliyun.comIf this fails, the gateway may be misconfigured.
Step 2: Check the gateway configuration
In the DSW instance configuration, check the Internet Access Gateway:
Public Gateway: The default option. Provides internet access with limited bandwidth, which can cause timeouts for large downloads.
Dedicated Gateway: Offers faster network access but requires manual setup — create an Internet NAT gateway in the Virtual Private Cloud (VPC), bind Elastic IP addresses (EIPs), and configure SNAT rules. For setup instructions, see Improve public network access speed with a dedicated gateway.
Step 3: Switch to a faster pip mirror
# Tsinghua mirror (recommended)
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn <yourLibraryName>
# USTC mirror
pip install -i https://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn <yourLibraryName>
# Douban mirror
pip install -i https://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com <yourLibraryName>To make a mirror change permanent, see Change the global pip mirror.
Step 4: Install offline
If the network is unavailable, install from a local wheel file:
On a machine with internet access, download the wheel file:
pip download <yourLibraryName> -d ./packagesUpload the
.whlfile to the DSW instance. See Upload and download files.Install from the uploaded file:
pip install /path/to/your-package.whl
How do I extract .zip or .7z files if unzip or 7z is not found?
Install the tools using apt-get in Terminal:
For `.zip` files:
apt-get update && apt-get install -y unzip unzip your_file.zipFor `.7z` files:
apt-get update && apt-get install -y p7zip-full 7z x your_file.7z
How do I get root permissions in the WebIDE terminal?
Most official DSW images provide a root shell by default. Check whether the terminal prompt shows root@.... The "pip running as root" warning can be safely ignored.
If the image does not provide root access, create a new instance using an image that does.
Can I run Docker commands inside a DSW instance?
It depends on the resource type. For Lingjun resources, submit a ticket to be added to the allowlist. For all other DSW instance types, Docker is not supported.
Can I start an X server or run GUI applications in a DSW instance?
No. DSW instances do not support X server or GUI applications.