Torch is not being found

hello,
can someone help me im trying to run a training script for a module and the first error i got in the command prompt is this :
ModuleNotFoundError: No module named ‘torch’

but i already have it installed here are the commands i ran and outputs i got :
C:\Users\moham\Desktop\mohamad\uni\thesis>pip install torch
Requirement already satisfied: torch in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (2.2.2)
Requirement already satisfied: filelock in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (3.13.1)
Requirement already satisfied: typing-extensions>=4.8.0 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (4.9.0)
Requirement already satisfied: sympy in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (1.12)
Requirement already satisfied: networkx in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (3.2.1)
Requirement already satisfied: jinja2 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (3.1.3)
Requirement already satisfied: fsspec in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from torch) (2024.2.0)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from jinja2->torch) (2.1.5)
Requirement already satisfied: mpmath>=0.19 in c:\users\moham\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from sympy->torch) (1.3.0)

C:\Users\moham\Desktop\mohamad\uni\thesis>where python
C:\Users\moham.pyenv\pyenv-win\shims\python
C:\Users\moham.pyenv\pyenv-win\shims\python.bat
C:\Users\moham\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Users\moham\Desktop\mohamad\uni\thesis>python -c “import site; print(site.getsitepackages())”
[‘C:\Users\moham\.pyenv\\pyenv-win\versions\3.13.0a6’, ‘C:\Users\moham\.pyenv\pyenv-win\versions\3.13.0a6\Lib\site-packages’]

Did you try uninstalling then installing it again?
Also try updating pip and checking your environment

multiple times but still not working , chatgbt gave me this reply :
Based on the output you provided, it seems that you are using a Python interpreter managed by pyenv, and the version is 3.13.0a6. However, PyTorch is not installed in this Python environment, as indicated by the absence of its path in the site-packages directories.

To resolve the issue and ensure that PyTorch is installed and accessible from your Python environment managed by pyenv, you can follow these steps:

  1. Activate pyenv Environment:
    If you have multiple Python versions installed via pyenv, make sure to activate the environment where you want to install PyTorch. You can do this using the pyenv global, pyenv local, or pyenv shell commands.

  2. Install PyTorch:
    Once you have activated the desired pyenv environment, you can install PyTorch using pip. Run the following command to install PyTorch:

    pip install torch torchvision torchaudio
    
  3. Verify Installation:
    After installation, you can verify that PyTorch is installed correctly by importing it in a Python interpreter session. Run the following command:

    python -c "import torch; print(torch.__version__)"
    
  4. Check Python Path:
    Double-check that the Python interpreter being used in your command prompt or terminal corresponds to the pyenv environment where PyTorch is installed. You can use the which python or where python command to check the Python interpreter location.

By following these steps, you should be able to install PyTorch in your pyenv environment and ensure that it is accessible from your Python interpreter. If you encounter any issues during the installation process, please let me know, and I’ll be happy to assist you further.

but that didnt work either

Please check or reset your python environment
I believe you might be using the Windows built-in environment which is quite risky. It’s better to download anaconda and python separately and away from windows/python.bat then add python, anaconda/scripts, python/scripts to your environment variables.

1 Like

working in anaconda environment worked thank you , but why does it glitch like that when i use the windows built in environment?