The platform’s built-in images all come with Miniconda installed, and the installation path is /root/miniconda3/.
If you need to use other versions of CUDA or cuDNN, you can easily set up the required environment in just a few steps using Miniconda. We recommend choosing the Miniconda image when creating an instance (it does not come with any deep learning frameworks pre-installed, keeping the runtime environment clean and avoiding unnecessary issues).The following example demonstrates how to use Conda to set up an environment for TensorFlow 1.15.0.
If you need to install the virtual environment on a data disk, please refer to the method described at the end of the document.
conda create -n tf python=3.7 # Create a virtual environment named "tf"conda init bash && source /root/.bashrc # Update the environment variables in bashrcconda activate tf # Switch to the created virtual environment "tf"
Here is an example of installing TensorFlow 1.15.0.
bash
# After switching to the Conda virtual environmentconda install tensorflow-gpu==1.15.0# Conda will automatically resolve and install the required CUDA and cuDNN versions for TensorFlow 1.15.0
python
# Simple test using Python after installationimport tensorflow as tfhello = tf.constant('Hello, TensorFlow!')sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))print(sess.run(hello))
How to Use the New Conda Environment in JupyterLab Notebook
bash
# Create a new Conda virtual environment (skip if already created)conda create -n tf python=3.7 # Create a virtual environment named "tf"conda init bash && source /root/.bashrc # Update the environment variables in bashrc# Add the new Conda virtual environment to JupyterLabconda activate tf # Switch to the created virtual environment "tf"conda install ipykernel # Install ipykernel to enable kernel integrationipython kernel install --user --name=tf # Set up the kernel for the environment, with "tf" as the kernel name
After executing the above commands, if you create a new Notebook, you can select the Notebook named “tf”.If it is an existing Notebook
# Clear the installed environmentconda deactivate # Exit the current (tf) environment and return to the base environmentconda remove -n tf --all # Remove the tf environment
Installing the Virtual Environment to the Data Disk
Execute the following commands to set up the virtual environment installation path to /root/guphub-tmp/conda/envs and the package cache path to /root/guphub-tmp/conda/pkgs:
# Check if the configured paths are in the file contentcat /root/.condarc
Cancelling the Configuration for Installing Virtual Environment to the Data DiskEdit the /root/.condarc file and delete the lines corresponding to the configured paths.