Tutorials  /  AI/ML

Install PyTorch on Debian 12 with pip or Anaconda

Ccentron Redaktion · August 2025 ·5 min read ·AI/ML, Tutorial

PyTorch is an open-source tensor computation framework created by Meta AI. It offers both CPU and GPU acceleration and is a popular choice for developing deep learning models in areas such as computer vision, natural language processing, and reinforcement learning.

This guide explains how to install PyTorch on Debian 12 using either pip or Anaconda, set up an isolated Python environment, and confirm the installation with a basic test script.

GPU

Need more GPU power for this project?

Dedicated NVIDIA GPUs (RTX A4000 to A100) from German data centers – from €92.59/month, billed by the hour, ready in minutes. Rent a GPU server →

Prerequisites

Before starting, ensure you meet the following requirements:

  • Access to a Debian 12 server as a non-root user with sudo privileges.

Create a Python Virtual Environment

To keep your PyTorch project isolated and prevent conflicts with system-level packages, create a virtual environment using the virtualenv tool.

First, confirm that Python 3.9 or newer is installed:

Console
$ python3 --version

Example output:

Code
Python 3.11.2

Check that pip is installed:

Console
$ pip --version

Example output:

Console
pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)

Install virtualenv:

Console
$ sudo apt install virtualenv -y

Create a new virtual environment named pytorch_project_env:

Console
$ virtualenv pytorch_project_env

Activate the virtual environment:

Console
$ source pytorch_project_env/bin/activate

The shell prompt will change to reflect the active environment:

Code
(pytorch_project_env) linuxuser@centron:~$

Choosing Between pip and conda

Use pip if you prefer a lightweight environment created with virtualenv or want to manually manage packages.

Use Anaconda if you already work with Conda environments or require a more comprehensive scientific computing stack with simplified dependency handling.

Both methods install the same PyTorch packages. Pick the option that aligns with your workflow.

Installing PyTorch with pip

To install the latest CPU-only version of PyTorch, use the official PyTorch wheel repository. Ensure your virtual environment is active before running the command:

Console
$ pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
  • torch: Core library for tensor computation and deep learning.
  • torchvision: Tools and models for computer vision.
  • torchaudio: Audio processing utilities for deep learning.

Installing PyTorch with Anaconda

Anaconda is a Python distribution with Conda for managing packages and environments. Use Conda to install PyTorch from the official PyTorch channel.

If Anaconda is not installed, follow its Debian 12 installation instructions before continuing.

Install the CPU-only version of PyTorch:

Console
$ conda install pytorch torchvision torchaudio cpuonly -c pytorch

When asked, confirm by typing y. The output will include messages such as:

Code
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Verifying the Installation

To confirm PyTorch is installed, start the Python interpreter:

Console
$ python

Example output:

Code
Python 3.11.2 (main) [GCC 12.2.0] on linux
Type "help", "copyright", "credits", or "license" for more information.
>>>

Import PyTorch:

Code
>>> import torch

Print the PyTorch version:

Code
>>> print(torch.__version__)

Example output:

Code
2.7.0+cu126

Create a random 5x3 tensor to test functionality:

Code
>>> x = torch.rand(5, 3)
>>> print(x)

Example output:

Code
tensor([[0.7363, 0.4839, 0.1370],
        [0.6429, 0.0108, 0.9823],
        [0.8575, 0.9642, 0.5792],
        [0.8951, 0.8762, 0.7949],
        [0.7175, 0.0135, 0.9493]])

Exit the interpreter:

Code
>>> exit()

Conclusion

You have installed PyTorch on Debian 12 using either pip or Anaconda and validated the installation with a test script. You can now begin creating and training deep learning models for tasks like computer vision, natural language processing, and reinforcement learning.

For further details and resources, check the official PyTorch documentation.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie AI/ML
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren