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

↘锁芯ラ 提交于 2021-02-10 05:37:14

问题


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!


回答1:


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.




回答2:


Add the conda environment to PATH.



来源:https://stackoverflow.com/questions/55786990/visual-studio-code-conda-and-python-environments-i-cannot-get-it-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!