Reputation: 25701
I am trying to learn Python and debug code for the first time in VS Code (latest edition). I have anaconda running and the code I have runs fine by itself but now I need to know how to update the code and debug it for the first time.
I keep getting the following error related to NumPy:
Exception has occurred: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
- The Python version is: Python3.7 from "C:\Miniconda2\envs\myproject_flask\python.exe"
- The NumPy version is: "1.18.5"
and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
In the Miniconda path above the Python.exe is version 3.7.7. I tried to install NumPy like so in myproject directory:
(myproject_flask) c:\MyProject\source\MyProject.Flask>conda install numpy=1.18.5
I still get the same error when I go to F5
to debug and run to a breakpoint.
Need help with my environment.
I need to use VS Code in my Windows environment with Anaconda.
Upvotes: 2
Views: 1474
Reputation: 21
I was getting the error even after adding all the anaconda paths, it was due to VScode running the code in the python debugger terminal which is not able to enter the conda environment.
This worked for me:
press ctrl+Shift+P
> Type Terminal:Select Default profile
> Select Command prompt
after this code ran in Command prompt by default, inside the environment.
Upvotes: 0
Reputation: 156
You should launch VS Code from Anaconda Navigator so that the environment is initialized.
Upvotes: 1
Reputation: 12295
When you have problems with importing the numpy C-extensions in Anaconda it's very likely that your virtual environment hasn't been activated. Having just Python on the path is not good enough. You also need access to the libraries. This is what the activation does.
When you are running/debugging code you should see a terminal open. You can tell from the prompt
(myproject_flask) C:\MyProject
that conda has been activated. Sometimes this just takes a bit too long for VSCode. So simply push the start button a second time.
Note that the Code Runner
extension in VSCode is also known to cause this kind of problems.
However, I wonder why you are using Miniconda2 with Python3, although in general this should work.
Upvotes: 0