2

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!

  • How are you running the code? By selecting "Run Python file In Terminal" from the CTRL-SHIFT-P menu? – darthbith Apr 22 '19 at 19:42
  • Hi @darthbith, I got it working. I checked the PATH variable and found that when I add the path to my conda environment which I named sci to PATH, it works with Visual Studio Code. The paths I added to PATH are 'C:\Python37\envs\sci', 'C:\Python37\envs\sci\Library\bin', and 'C:\Python37\envs\sci\Scripts'. – Hannes Ziegler Apr 24 '19 at 01:33

2 Answers2

4

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.

JHuw
  • 250
  • 2
  • 12
0

Add the conda environment to PATH.