Spaces:
Sleeping
To create a **virtual environment (venv)** using **Python 3.11** or older
To create a virtual environment (venv) using Python 3.11 while your system has Python 3.13 installed, follow these steps:
๐ ๏ธ Step-by-Step Instructions
1๏ธโฃ Check Installed Python Versions
First, confirm that Python 3.11 is installed on your system.
Run this command:
python3 --version
or
python --version
If it returns Python 3.13, you need to check if Python 3.11 is available.
๐ Windows:
List available Python versions:
py --list
If Python 3.11 appears, use py -3.11 instead of python.
๐ macOS/Linux:
List installed Python versions:
ls /usr/bin/python*
If you see /usr/bin/python3.11, you can use python3.11 instead of python.
2๏ธโฃ Create a Virtual Environment Using Python 3.11
Run one of the following commands depending on your OS:
๐ Windows (PowerShell / CMD)
py -3.11 -m venv myenv
or (if py -3.11 does not work)
C:\Path\To\Python311\python.exe -m venv myenv
๐ macOS/Linux
python3.11 -m venv myenv
or (if python3.11 is not recognized)
/usr/bin/python3.11 -m venv myenv
This will create a virtual environment named myenv.
3๏ธโฃ Activate the Virtual Environment
Once the virtual environment is created, activate it:
๐ Windows (PowerShell)
myenv\Scripts\Activate
๐ Windows (CMD)
myenv\Scripts\activate.bat
๐ macOS/Linux
source myenv/bin/activate
After activation, your terminal should show something like:
(myenv) user@computer:~$
4๏ธโฃ Install PyTorch for Python 3.11
Now that you have the virtual environment, install PyTorch:
๐ For CPU (No CUDA)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
๐ For GPU (CUDA 11.8)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
5๏ธโฃ Verify the Installation
Run Python inside your virtual environment:
python
Then, test if PyTorch is installed correctly:
import torch
print(torch.__version__)
print(torch.cuda.is_available()) # Should return True if GPU is available
6๏ธโฃ Use the Virtual Environment
Now, whenever you need to run your project, activate the environment first:
source myenv/bin/activate # macOS/Linux
myenv\Scripts\Activate # Windows (PowerShell)
To deactivate the environment, simply run:
deactivate
โ Summary
1๏ธโฃ Ensure Python 3.11 is installed.
2๏ธโฃ Create a virtual environment:
- Windows:
py -3.11 -m venv myenv - macOS/Linux:
python3.11 -m venv myenv
3๏ธโฃ Activate the environment.
4๏ธโฃ Install PyTorch usingpip.
5๏ธโฃ Verify the installation.
6๏ธโฃ Usesource myenv/bin/activate(ormyenv\Scripts\Activateon Windows) to activate it when needed.
Now your environment is set up with Python 3.11 and PyTorch! ๐