Search code examples
pythonnumpycommand-lineanacondaimporterror

numpy works well in Jupyter Notebook, but not in command line


I am trying to schedule my py file in command line, it has been tested in jupyter notebook, and the ipynb file works well. But when the py file runs in command line, it shows the problem:

Traceback (most recent call last): File "test_np.py", line 9, in <module> import numpy as np File "C:\Users\xxx\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module> from . import _distributor_init File "C:\Users\xxx\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module> from . import _mklinit ImportError: DLL load failed: The specified module could not be found.

I have investigated the problem, and found one of the similar problem from link, but my Anaconda3 has been installed under Users\xxx\Anaconda3. I am wondering:
1. Whether the path variables is the reason of the problem?
2. If it is, should the Anaconda3 been reinstalled under ProgramData?
3. If the path variables isn't the reason, what is the possible reason?
Thanks.


Solution

  • It seems this problem caused by the path variables . It has been soved by:
    adding 5 variables as below to PATH variables:
    \anaconda3
    \anaconda3\Library\mingw-64t
    \anaconda3\Library\usr\bin
    \anaconda3\Library\bin
    \anaconda3\Scripts