Create a conda environment and use it in a no-internet machine

1 minute read

Published:

This post will talk about how to create a conda environment and use it in a machine without internet.

First, we need to download a conda program at the machine you are using with internet, see here.

Then, we create an environment with target pytorch and CUDA version that are matched with our GPU model. For example, we can install pytorch==1.11.0 and CUDA=11.3 by runnung conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch, see here

In China mainland, we might need to use a local conda channels, see here.

After install all packages, we can check pytorch and CUDA version by

import torch
print(torch.__version__)
print(torch.version.cuda)
print(torch.cuda.get_device_name(0))
print(torch.cuda.is_available())

Then we can pack our conda environment into a file by conda pack -n [the name of your environment], we might need to install the pack command by conda install conda-pack (see here), we might also add -o and -p arguments to specify the name and path of the generated zip file, respectively.

Finally we can unzip the environment at our machine without internet, e.g.,

mkdir -p my_env
tar -xzf my_env.tar.gz -C my_env
source my_env/bin/activate # activate the environment
source my_env/bin/deactivate # deactivate the environment