Hannes Ziegler
Hannes Ziegler

Reputation: 187

Visual Studio Code, Conda, and Python Environments (I cannot get it working)

I am setting up Visual Studio Code on my pc and am running into difficulties with the python environment I created and Visual Studio Code.

However, when running some test code, I get an import error..

I installed Python 3.7.3 with miniconda to 'C:\Python37', and then created a clone of the base environment named 'sci' and installed some packages (numpy, pandas, matplotlib, scipy, scikit-learn) using cmd. I tested the install in cmd with commands as follows:

conda activate sci 
python
import numpy
print(numpy.array([1, 2, 3]))

and everything works fine.

I then installed Visual Studio Code (.zip, not with installer) to 'C:\VisualStudioCode', opened a folder for testing and used the 'Python: Select Interpreter' command to specify the sci environment I created above. Now when I run the following code I get an import error message:

import numpy
numpy.array([1, 2, 3])

ImportError: DLL load failed: The specified module could not be found.

Any idea why this is happening? The bottom left of my VS Code window states Python 3.7.3 64-bit ('sci': conda), but when typing conda env list into the VS Code terminal it still points to the base environment, so that might be a clue..

Thank you for any suggestions!

Upvotes: 2

Views: 2730

Answers (2)

Hannes Ziegler
Hannes Ziegler

Reputation: 187

Add the conda environment to PATH.

Upvotes: 0

JHuw
JHuw

Reputation: 250

After much frustration trying to follow other solutions, this is what finally worked for me (on a Windows 10 machine) with Anaconda python installed.

  • Open an Anaconda Prompt terminal.
  • Choose the conda environment you want (e.g. conda activate myenv1)
  • Finally type code from the command line to launch visual studio code.

When I do that and then open any python file and click 'Run Python File in Terminal' (triangle in top right of editor) and all runs well.

Upvotes: 4

Related Questions