0

I have cleanly and successfully installed PyTorch and associated packages within my virtual environment (BotVirtualEnv). It passed all required tests, including that of Python Interpreter and ensured it's selected within VSCode. In my neural_net.py script I created the following import statements (import torch, import torch.nn as nn, import torch.optim as optim) with which to work. The code itself is clean with no syntactic errors, yet the interpreter keeps throwing the below error:

Traceback (most recent call last):
  File "/Users/sBliss_/Trading-Algorithm/src/neural_net.py", line 1, in <module>
    import torch
ModuleNotFoundError: No module named 'torch'

I am here only because I have exhausted every troubleshooting knowledge that I have. I even created an environment variable and pointed the interpreter to it as well, and all to NO avail. Someone please help.

8
  • 1
    Are you sure that you are running this code inside your virtual environment? If Python cannot find the module then it is most likely that you are not. Commented Jun 5, 2024 at 13:40
  • OldBoy, thanx for your response. The answer to your question is a definite YES. Please see below: /Users/sBliss_/Trading-Algorithm/BotVirtualEnv/bin/python /Users/sBliss_/Trading-Algorithm/src/neural_net.py /Users/sBliss_/Trading-Algorithm/BotVirtualEnv/bin/python /Users/sBliss_/Trading-Algorithm/src/neural_net.py Traceback (most recent call last): File "/Users/sBliss_/Trading-Algorithm/src/neural_net.py", line 1, in <module> import torch ModuleNotFoundError: No module named 'torch' Commented Jun 5, 2024 at 20:01
  • Well it is clear that one of these is the answer: 1. You have not activated the virtual environment where torch is installed. or 2. You have activated it, but you installed torch somewhere else. Please update your question with a folder list showing where torch is installed, and an execution of the program starting with the command that activates the virtual environment. Commented Jun 5, 2024 at 20:52
  • SFN_ source /Users/sBliss_/Trading-Algorithm/BotVirtualEnv/bin/activate (BotVirEnv) SFN_ pip3 list Package Version ----------------------------- ------------ torch 2.2.2 torchaudio 2.2.2 torchvision 0.17.2 tornado 6.2 (BotVirEnv) SFN_ pip3 show torch Name: torch Version: 2.2.2 Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration Homepage: pytorch.org Author: PyTorch Team. Text abbreviated for space constraints. Commented Jun 5, 2024 at 22:33
  • That output is different from the previous post, and your question. Can you please update your question (using the Edit link) with the complete details from calling activate to actually trying to run the code? Commented Jun 6, 2024 at 9:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.