Home >Backend Development >Python Tutorial >Install PyTorch and JupyterLab on Ubuntu

Install PyTorch and JupyterLab on Ubuntu

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-12 12:09:43390browse

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>

Install PyTorch and JupyterLab on Ubuntu

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn