I want to run a python script in cmd via a batch file. The script fails with dll loading error for numpy imports. The same python script works in pycharm (2019 Anaconda Version) and in the anaconda command prompt without errors.
For all I use the same anaconda enviorment.
For Error Reproduction
- Install Anaconda, don't set any path variables
- Create an enviorment stored not in the default folder
- conda create --prefix
- conda activate
- conda install numpy flask 6.Code for testing. test-numpy.py
import numpy as np
print(np.abs([1,2-4,6]))
create batch script run batch script
Running in cmd a python script that has only system imports or no imports works fine. Setting the pythonpath Variable in Windows is no option. What I did so far: Checking if there is an PATH error: I printed the sys.path, both via Pycharm and the same python script run via CMD gave the same results: it points to my anaconda enviorment with the folders: ...\ (the enviorment itself) ...\python37.zip ...\DLLs ...\lib ...\lib\site-packages
Edit
Tested in Visual Studio Code, gives same Error as running via cmd
- Found out Visual Studio Coda until now, can't handle conda enviorments, that where installed with -p or -prefix and are not stored in the default path
Uninstalled and reinstalled numpy Tested to import another module: Flask also fails with DDL load error but works fine while run in Pycharm. Tested on another PC with differnt anaconda version. Another person could reproduce the same error I get.
My guess is my code fails in cmd, becaust anacona enviorments needs somehow to be activated before hand and doesn't work as a stand alone.
The Error Messeag I get running my script in CMD (... points to my anaconda enviormant path):
...\lib\site-packages\numpy\core__init__.py", line 40, in from . import multiarray ...\lib\site-packages\numpy\core\multiarray.py", line 12, in from . import overrides ...\lib\site-packages\numpy\core\overrides.py", line 6, in from numpy.core._multiarray_umath import ( ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): "TestNumpy.py", line 14, in import numpy as np ...\lib\site-packages\numpy__init__.py", line 142, in from . import core ...\lib\site-packages\n umpy\core__init__.py", line 71, in raise ImportError(msg) ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Mostlikely you are trying to import a failed build of numpy. Here is how to proceed: - If you're working with a numpy git repository, try
git clean -xdf
(removes all files not under version control) and rebuild numpy. - If you are simply trying to use the numpy version that you have installed: your installation is broken - please reinstall numpy. - If you have already reinstalled and that did not fix the problem, then: 1. Check that you are using the Python you expect and that you have no directories in your PATH or PYTHONPATH that can interfere with the Python and numpy versions you're trying to use. 2. If (1) looks fine, you can open a new issue at https://github.com/numpy/numpy/issues. Please include details on: - how you installed Python - how you installed numpy - your operating system - whether or not you have multiple versions of Python installed - if you built from source, your compiler versions and ideally a build logNote: this error has many possible causes, so please don't comment on an existing issue about this - open a new one instead.
Original error was: DLL load failed: Das angegebene Modul wurde nicht gefunden.