If you're not very familiar with computer technology but need to use some AI-related software (such as video translation, voice cloning, text-to-image, etc.), you might need to install Python on your computer. Python is a programming language that many AI software programs rely on to run. This article will guide you step-by-step to install Python 3.10.4 on Windows 10 and configure a simple environment to run these software programs.
Why Choose Python 3.10.4?
Because it's a relatively stable version:
• Versions lower than 3.10 may have been abandoned by some software. • And higher versions (like 3.11 or 3.13) might be too new, and model modules may be incompatible.
Step 1: Download Python 3.10.4
- Open a browser: Use your preferred browser and enter the following address in the address bar, then press Enter to open the download page:
https://www.python.org/downloads/release/python-3104/
Find the download link: Scroll down the page until you see the "Files" section. Find the "Windows installer (64-bit)" line and click to download it (the downloaded file name will be
python-3.10.4-amd64.exe
).Save the file: The download will start automatically, and the file will be saved to your "Downloads" folder (usually located at
C:\Users\Your Username\Downloads
).
Step 2: Install Python 3.10.4
Start the installation: Find the downloaded
python-3.10.4-amd64.exe
file and double-click it. The installation window will pop up. • Important: In the options at the bottom of the window, check "Add Python 3.10 to PATH", and then click "Install Now".Wait for the installation to complete: The installation process may take a few minutes. Once complete, you will see a "Setup was successful" message. Click "Close" to exit the installer.
Step 3: Check if Python is Installed Successfully
- Open the command line terminal (CMD): Press and hold the Windows key + R on your keyboard, and the "Run" window will pop up. Enter
cmd
in the input box, and then press Enter. This will open a black command line window.
- Enter the command to check Python: In the command line window, enter the following and press Enter:sh
python --version
If you see output similar to Python 3.10.4
, congratulations, the installation was successful! If there is no response or an error, it may be because "Add Python 3.10 to PATH" was not checked, and you need to reinstall.
Step 4: Create a Virtual Environment
A virtual environment is like an independent "small room" that allows different AI projects to use different software versions, avoiding conflicts. We use Python's built-in venv
module to create it.
- Choose a folder: For example, you can create a folder on the D drive to store your projects. It is recommended to use a folder name with a combination of English or numbers, without Chinese or spaces and special symbols, such as
D:/AIProject
. - Enter the folder and open the command line: Enter
D:/AIProject
, entercmd
in the folder address bar, and press Enter to open the terminal.
- Create a virtual environment: In the command line opened in the previous step, enter:sh
python -m venv myenv
After pressing Enter, a subfolder named myenv
will be added to the folder, which is your virtual environment. 4. Activate the virtual environment: Enter the following command and press Enter:
myenv\Scripts\activate
If successful, you will see (myenv)
added to the front of the command line, indicating that you have entered the virtual environment.
Step 5: Install Dependencies in the Virtual Environment
Suppose you have an AI model project with a requirements.txt
file (usually a list of dependencies provided by the software author). Let's install it.
- Make sure the file is in the correct location: Copy
requirements.txt
to your "AIProject" folder. - Install dependencies: In the activated virtual environment (command line has
(myenv)
), enter:shThis will automatically download and install all the packages listed in the file.pip install -r requirements.txt
- Solve common problems: • Network error: If you see "Connection timeout" or "Download failed", it may be a network problem. You can try changing the network, or try a few more times. You can also add a domestic mirror to speed up the download, enter:sh• Dependency conflict: If you see that a package version is incompatible, try updating pip:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
shThen rerun the installation command. If it still doesn't work, you can contact the software author and ask for a compatible version.pip install --upgrade pip
Step 6: Install PyTorch (Supports CUDA 12.4)
If you have an NVIDIA graphics card and have installed CUDA 12.4 or higher (if not, you can skip this part and check other tutorials to install CUDA), you can use the following steps to install GPU-supported PyTorch.
- Check virtual environment activation: Make sure the command line has
(myenv)
. - Install PyTorch: Enter the following command and press Enter:shIf the CUDA version you installed is greater than 12.4, you can change
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
cu124
in the above command tocu126
. If it is lower than 12.1, you can change it tocu118
.torch
is the PyTorch main library,torchvision
processes images, andtorchaudio
processes audio.--index-url
specifies the download address for the CUDA 12.4 version. - Verify installation: Enter the following command:sh
python -c "import torch;print(torch.__version__);print(torch.cuda.is_available())"
If the output is similar to 2.6.0
(version number) and True
, it means the installation was successful and the GPU is available. If it is False
, check whether CUDA is installed correctly. If it is No module named 'torch'
, it means the above command failed to install torch
.
Note: Requires an NVIDIA graphics card and a CUDA 12.4 environment. If not, you can use the CPU version, the command is:
pip install torch torchvision torchaudio
Finally: Run Your AI Software
Now the environment is configured! If your AI software has specific running instructions (such as python run.py
), enter the corresponding command in the virtual environment.