Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Code Runner doesn't work with virtualenvs

Tags:

I can't get Code Runner extension to work with virtualenvs. Whenever I try to run code that imports a library that is installed only in the virtualenv and not in the global Python installation I get an import error. Running the exact same code in terminal works.

I am on Windows 10 and I have Python 3.6.5 installed.

The precise error I am getting is:

ModuleNotFoundError: No module named 'bs4' 
like image 532
slinden Avatar asked Jun 21 '18 10:06

slinden


People also ask

Why is my code not running in VS code?

You can check and disable compatibility mode by right-clicking on the VS Code executable and selecting properties, then uncheck the Run this program in compatibility mode option in the compatibility tab.

How does VSCode choose an interpreter?

To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).


1 Answers

I also faced same issue.

enter image description here solution which i found best is just add this line to your user or workspace settings(whichever is suits your projects):

"code-runner.executorMap": {     "python": "C:\\Users\\adarsh_patel\\VisualCode\\env\\Scripts\\activate.bat && python -u", } 

you have to enter your virtualenv path or you could use.

"code-runner.executorMap": {"python":"$pythonPath $fullFileName"} 

enter image description here

enter image description here

hope this helps you.

like image 113
Adarsh Patel Avatar answered Sep 24 '22 17:09

Adarsh Patel