Create Python Environment
Creating a dedicated Python environment for Candy Bot helps manage dependencies and avoid conflicts with other Python projects.
Initial Setup
-
Create a new folder named "candy" on your desktop.
-
Open Command Prompt in the "candy" folder:
-
Create a new Python virtual environment by typing:
python -m venv env
-
Activate the virtual environment:
env\scripts\activate
You should see
(env)
at the beginning of your command prompt, indicating that the virtual environment is active. -
Install PyTorch with CUDA support:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
Verify GPU Setup
-
After installing PyTorch, let's verify the GPU setup. Create a new file named
check_gpu.py
in your "candy" folder with the following content:import torch
import os
def checkGPU():
status = torch.cuda.is_available()
if status:
os.system('color 0a')
else:
os.system('color 0c')
os.system('cls')
print(f"PyTorch GPU Status: {status}")
if status:
try:
print(f"GPU name: {torch.cuda.get_device_name(0)}")
gpuMemory = round(torch.cuda.get_device_properties(0).total_memory/1000000000, 2)
print(f"GPU memory: {gpuMemory} GB")
except:
print("GPU is unavailable")
if __name__ == "__main__":
checkGPU() -
Run the GPU check script:
python check_gpu.py
This script will display information about your GPU status, including whether PyTorch can use your GPU, the GPU name, and its memory capacity.
- If the output is green, it means PyTorch can use your GPU.
- If the output is red, it means PyTorch cannot use your GPU, and you may need to troubleshoot your setup.
Troubleshooting Common Issues
Missing DLL Error
If you encounter this error when importing torch:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\pc\ali\Lib\site-packages\torch\__init__.py", line 141, in
raise err
OSError: [WinError 126] The specified module could not be found. Error loading "C:\Users\lestey\Lib\site-packages\torch\lib\fbgemm.dll" or one of its dependencies.
Follow these steps to resolve the issue:
-
Download and Install DLL:
- Download libomp140.x86_64_x86-64.zip
- Extract the ZIP file
- Press
Windows + R
, type%windir%\system32
, and press Enter - Copy the extracted DLL file into the System32 folder
- Click "Continue" if prompted for administrator permission
-
Verify the Fix:
- Close your current Command Prompt
- Open a new Command Prompt
- Run:
env\scripts\activate
python check_gpu.py
If the script shows that PyTorch cannot use your GPU, ensure that you have correctly installed the NVIDIA drivers and CUDA as described in the NVIDIA Setup section.
Administrator privileges are required to modify the System32 folder. Contact your system administrator if you don't have the necessary permissions.
What's Next?
Now that your Python environment is set up and you've verified your GPU status, you're ready to move on to installing the required packages for Candy Bot.
Remember to keep your virtual environment activated while working with Candy Bot. If you close your Command Prompt, you'll need to activate it again using env\scripts\activate
when you return to work on the project.