-1

So yesterday i noticed that the vscode terminal was using the global pip instead of the pip in my virtual environment when trying to use pip or package commands. Running the python file is no problem. I haven't been able to fix this since.

'pip list' command from vscode terminal

Here is the same command from cmd window:

'pip list' command from command prompt

2 Answers 2

0

This very likely means that your vscode terminal uses also the wrong Python environment and another Python executive than your project uses.

Set the Python Interpreter in VS Code
    1.  Open VS Code.
    2.  Open the Command Palette (Cmd + Shift + p) 
                                         (or: Ctrl + Shift + p)
    3.  Search for Python: Select Interpreter.
    4.  Select “Enter interpreter path” → “Find…”.
    5.  Navigate to the Python path of your project 
                (`which python` might help to clarify that from within 
                your project's python - if you are in windows, 
                install scoop and install linux tools using scoop install).
    6.  Confirm selection.
Sign up to request clarification or add additional context in comments.

2 Comments

The interpreter path is set correctly. I can run my python file with the 'run python file' triangle/arrow. Its the terminal which doesn't use the selected interpreter. When i type 'python main.py' in the terminal it uses the global python (which doesnt have te required packages for my project)
ah ok. Then you should activate the virtual environment manually in the terminal again. before you call python main.py.
0

From your screenshots it appears that you do not have a virtual environment in your Windows DOS shell. Use a Linux command line emulator such as git bash or WSL. Setup `.bash_profile` with the following … source /.venv/bin/activate. To create a venv `python3 -m venv .venv `. In addition, you need to tell Code which interpreter to use. This is found here Selecting python interpreter in VSCode

2 Comments

I do have a virtual environment (mLibVenv312) and it is set as default interpreter for my vscode as you can see in the bottom right corner of the first screenshot. Clicking the 'run python file' triangle/arrow works, but i can't run it with 'python main.py' command in the vscode terminal. Thats where it takes the wrong interpreter.
Did you run <path to you venv>/bin/activate.bat (Activate.ps if PS) ?

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.