Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Visual Studio Code within Anaconda Env

I am running into trouble running a python program inside visual studio code on my Windows 10 PC.

When I start a python session from the terminal and say import cv2 I get no errors:

enter image description here

When I go through the command prompt and start VSCode from within the env, I get the ModuleNotFoundError

enter image description here

Traceback (most recent call last): File "gui.py", line 3, in <module> import cv2 ModuleNotFoundError: No module named 'cv2'

When I try to run the program as python gui.py from within the environment my command prompt crashes with the error message:

enter image description here

I'm not sure how to ask this question other than wondering is there a way to start my IDE from within the python env so that it can locate all the local packages.

like image 966
Q.H. Avatar asked May 15 '18 23:05

Q.H.


People also ask

How use Anaconda virtual environment in VS Code?

From within VS Code, you can create non-global environments, using virtual environments or Anaconda, by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Create Environment command to search, and then select the command. The command presents a list of environment types: Venv or Conda.


1 Answers

  1. Make sure you have visual studio code installed in your system.
  2. Make sure your environment variables are configured. (see below image for reference) enter image description here

  3. Go to your Anaconda command prompt, and type code --version (see below image for reference) enter image description here

  4. To Launch VS code from Anaconda/Window command prompt type code. (see below image)

enter image description here

like image 184
Manjeet Avatar answered Sep 18 '22 15:09

Manjeet