
PyTorch is an open-source tensor computation library developed by Meta AI. It supports GPU and CPU acceleration and is widely used for building deep learning models in applications like computer vision, NLP, and reinforcement learning.
This article shows you how to install PyTorch on Debian 12 using either pip or Anaconda, create an isolated Python environment, and verify the installation with a simple test script.
Before you begin, you need to:
To isolate your PyTorch project and avoid system-level conflicts, create a virtual environment using the virtualenv tool.
Verify that Python 3.9 or later is installed.
Output:
Confirm that pip is available.
Output:
Install virtualenv.
Create a new virtual environment named pytorch_project_env.
Activate the virtual environment.
The shell prompt changes to indicate the active environment.
pip vs. condaUse pip if you're working in a lightweight virtual environment using virtualenv or prefer to manage packages manually.
Use Anaconda if you're already using Conda environments or need access to a broader scientific computing stack with simplified dependency management.
Both methods install the same PyTorch libraries. Choose the one that best fits your development setup.
To install the latest CPU-only version of PyTorch, use the official PyTorch wheel repository with pip.
Make sure your virtual environment is active.
Install PyTorch and related packages.
torch: Core PyTorch library for tensor computation and deep learning.torchvision: Utilities and pretrained models for computer vision.torchaudio: Audio processing tools for deep learning applications.You can verify your PyTorch installation by launching the Python interpreter and running a few basic commands.
Open the Python interpreter.
Output:
Import the PyTorch package.
Print the installed PyTorch version.
Output:
Generate a 5x3 tensor of random values to confirm basic functionality.
The output should be similar to:
To exit the interpreter, type:
You successfully installed PyTorch on a Debian 12 server using either pip or Anaconda and verified the setup with a test script. With PyTorch, you can now build and train deep learning models for computer vision, natural language processing, and reinforcement learning.
To explore additional libraries and capabilities, visit the official PyTorch documentation.
0 Comments
Be the first to comment and share your perspective with the community.