-1

I am running a python script on VS Code and I am getting a package importing error but only the first time I run it after opening VS Code. If I run the same script again I don't get any errors, which makes me think there is something important being loaded only after I run it the first time. Any ideas of what might be causing this? I am running a python script imports numpy (or pandas, which uses numpy). The error is shown below.

Exception has occurred: ImportError Unable to import required dependencies: numpy:

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.

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.8 from "C:\Users\gcampos.conda\envs<env name>\python.exe"
  • The NumPy version is: "1.23.3"

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 while importing _multiarray_umath: The specified module could not be found.

To be clear, what is baffling to me is that the same script runs on the second try. Any thoughts on why?

Thank you.

gcampos
  • 1
  • 1

1 Answers1

0

This seems to be a solved problem. You can refer to this answer.

Add the following path to the system environment variable PATH (Note that this needs to be adjusted according to your actual path. The comment supplied that adding...\Scripts and... \Library\bin solves this problem):

C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Scripts\
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Library\
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Library\bin\
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Library\mingw-w64\bin\
MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13
  • Thanks. I am more concerned about the fact that it errors out the first time I run it but runs correctly the second. I tried changing the PATH variable as you suggested by I am now getting another DLL import error (also only the first time I run it, but not the second). – gcampos Nov 22 '22 at 23:49
  • Is there a problem running other python files (excluding numpy)? I think it would be a good choice to ask developers questions in [numpy's github](https://github.com/numpy/numpy). – MingJie-MSFT Nov 23 '22 at 06:20
  • I didn't think so initially. But after changing the path variables I did get a DLL import error for a package that was not numpy (forgot which one it was). Thanks, gonna give that a shot. – gcampos Nov 23 '22 at 19:43