Home >Backend Development >Python Tutorial >Install PyTorch and JupyterLab on Ubuntu
Let's get you set up with PyTorch and JupyterLab on Ubuntu! This guide provides a streamlined approach to installing and configuring everything you need.
First, ensure your Ubuntu system is up-to-date:
<code class="language-bash">sudo apt update && sudo apt -y upgrade</code>
Check your Python version. Note the version number (e.g., 3.13.x) as it will be needed in the next step.
<code class="language-bash">python3 --version</code>
Install the appropriate python3.xx-venv
package, matching your Python version. If your Python version is 3.13.x, replace 3.12
below with 3.13
.
<code class="language-bash">sudo apt install -y python3.12-venv</code>
Create a virtual environment (this keeps your project dependencies separate):
<code class="language-bash">python3 -m venv venv</code>
Activate the virtual environment:
<code class="language-bash">source venv/bin/activate</code>
Install PyTorch with CUDA 11.8 support. (Remember to adjust cu118
if you're using a different CUDA version or a CPU-only build; see the PyTorch website for options).
<code class="language-bash">pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118</code>
Install JupyterLab:
<code class="language-bash">pip install jupyterlab</code>
Launch JupyterLab, optionally specifying your working directory. Replacing /home/kai
with your desired directory.
<code class="language-bash">jupyter lab --notebook-dir /home/kai</code>
You're all set! Open your preferred web browser (like Firefox) and navigate to the URL JupyterLab provides in your terminal to begin working. Remember to deactivate the virtual environment when you're finished using deactivate
.
The above is the detailed content of Install PyTorch and JupyterLab on Ubuntu. For more information, please follow other related articles on the PHP Chinese website!