1

my python code works in spyder, but errors when run in cmd:

C:\Users\XYZ\AppData\Local\Continuum\anaconda3>python.exe "C:\\Users\\XYZ\\project_1\\Model\\PPP_2_main.py"

Traceback (most recent call last):
  File "C:\\Users\\XYZ\\project_1\\Model\\PPP_2_main.py", line 8,
 in <module>
    import numpy as np
  File "C:\Users\XYZ\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\XYZ\AppData\Local\Continuum\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 read this and it says python can't locate the module, and we need to add sys path. But isn't the error msg mentioning the correct path to the numpy library?

Confirm the path to library is correct (in sypder):

import numpy 
numpy.__file__
Out[5]: 'C:\\Users\\XYZ\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\numpy\\__init__.py'

Check conda env:

(base) C:\Users\XYZ>conda env list
# conda environments:
#
base                  *  C:\Users\XYZ\AppData\Local\Continuum\anaconda3

The path of the base env is where i was when running the code in cmd


I read this and tried to activate conda, and it didn't work. In conda cmd:

(base) C:\Users\zhayuji>conda activate base

(base) C:\Users\zhayuji\AppData\Local\Continuum\anaconda3>conda activate base

(base) C:\Users\zhayuji\AppData\Local\Continuum\anaconda3>conda list
# packages in environment at C:\Users\zhayuji\AppData\Local\Continuum\anaconda3:

#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0                    py37_0
_py-xgboost-mutex         2.0                       cpu_0
alabaster                 0.7.12                   py37_0
anaconda-client           1.7.2                    py37_0
anaconda-navigator        1.9.7                    py37_0    anaconda
....
numpy                     1.16.2           py37h19fb1c0_0
numpy-base                1.16.2           py37hc3f5095_0
numpydoc                  0.9.1                      py_0

After this i reopen cmd and ran python code, and it's the same err as at the beginning of the post.

YJZ
  • 3,934
  • 11
  • 43
  • 67
  • you must have a conda environment set up. try running `conda env list` and see which conda environments you have – hysoftwareeng Aug 09 '19 at 14:09
  • @LeBronJames thank u! The base path is just where I ran the code. Does it mean the env should be all set? – YJZ Aug 09 '19 at 14:18
  • yeah so that means your numpy should be installed on your base env if you did it correctly, try running in your conda prompt `activate base`, then run `pip list` and `conda list` to see if you see your numpy package – hysoftwareeng Aug 09 '19 at 14:21
  • thanks @LeBronJames. I did activation and conda list shows numpy. But still have the error... – YJZ Aug 09 '19 at 14:37

1 Answers1

2

I just checked with a colleague who had essentially the same problem, I think the mentioned link is correct.

Step 1 Edit Environment Variables - you can use this for your Account without requiring Admin Access (at least in Windows 10) enter image description here

Then you add these paths, I am rather confident that the library/bin one is the most relevant here as this is the problem. Your python executed from the windows command line does not know where to find the additional libraries. enter image description here

You might need to open a new command line interface - then it should work!

Community
  • 1
  • 1
El Burro
  • 188
  • 9