MATH ASKER
MATH ASKER

Reputation: 53

ModuleNotFoundError in Visual studio for python

I was trying to follow this video posted: https://www.youtube.com/watch?v=ySRQsrkrVCU

I setup a virtual environment following this video: https://www.youtube.com/watch?v=Wuuiga0wKdQ made the requrement.txt file here

enter image description here

and installed it here enter image description here

now when I try to run my code I get an error saying Modulenotfound no module named 'yfinance' I am confused as to what the problem is for this, I also had a general question about virtual environment in VS code, every time I start a new project, will I have to go through the video and make new path or is there a terminal code I can run?

enter image description here

enter image description here

Upvotes: 2

Views: 431

Answers (2)

pazitos10
pazitos10

Reputation: 1709

You have at least 2 different problems:

  1. In the third image you are trying to execute a python script with a Python binary that is not in your virtualenv.
  2. VS code may not be configured right to use your virtualenv's python interpreter.

Edit: it may only be the 2 if the third image is a screenshot from your VS Code terminal and not an external cmd and assuming you are running your Python code within the editor tools.

If that's the case, check your launch.json file in VS code. It should be something like this:

{
    "version": "0.1.0",
    "configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "python": "<path to your virtualenv>/bin/python",
            "program": "${fileBasename}",
        }
    ]
}

Make sure your "python" is pointing to the right python binary a.k.a. the one in your virtualenv path.

Then in VS code's general settings you can set "venvFolders" as a list of paths where your virtual environments were defined.

{
 ...
 "python.venvFolders:" ["<venv path 1>", "<venv path 2>"]
}

Check out the official guide: and another one related to the general settings.

Upvotes: 2

Nora
Nora

Reputation: 161

The reason for this issue may be because your application doesn't use the right Python interpreter or you haven't setup the PYTHONPATH for this application yet.

Trying saving this script as .bat file then put it under your source code then execute this .bat file. Then trying executing your application again.

@echo off
echo ---------SETUP PYTHON PATH---------
echo %cd%
setx PYTHONPATH %cd%
echo -----------------------------------------
pause

Upvotes: 0

Related Questions