question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Numpy importing with BAT file execution fails

See original GitHub issue

Reproducing code example:

I am trying to execute a .py file by running a .bat file through task scheduler. When I do that I get the error message below. When I run the .py file in an ide (I work w/ spyder I don’t have this problem) I have tried to uninstall numpy several times. I have reinstallaed several versions. I have tried w/ 1.16.6 but now working w/ 1.18.1

Obviously. Thank you in advance for any help you can provide.

import numpy as np

Error message:

C:\Users\GB New Lenovo\Anaconda\Install\lib\site-packages\numpy_init_.py:140: UserWarning: mkl-service package failed to import, therefore Intel® MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service from . import distributor_init Traceback (most recent call last): File “D:\Resilio\Nanodegree 1\Finance\Scraping_code\WSJ_bond_benchmark\WSJ_Bond_Benchmarks.py”, line 10, in <module> import pandas as pd File "C:\Users\GB New Lenovo\Anaconda\Install\lib\site-packages\pandas_init.py", line 17, in <module> “Unable to import required dependencies:\n” + “\n”.join(missing_dependencies) 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.

  • Try uninstalling and reinstalling numpy.

  • If you have already done that, then:

    1. Check that you expected to use Python3.6 from “C:\Users#########\Anaconda\Install\python.exe”, and that you have no directories in your PATH or PYTHONPATH that can interfere with the Python and numpy version “1.18.1” 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 log
  • If you’re working with a numpy git repository, try git clean -xdf (removes all files not under version control) and rebuild numpy.

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

Numpy/Python version information:

numpy version 1.18.1 Windows 10 Pro Version 1903 OS Buil 18362.657

I installed numby through anaconda prompt I beleive I installed python w/ the anaconda installation I have python 2.7 and python 3.6 installed.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
pjdoncommented, Mar 7, 2020

@mattip Thank you for clarifying, that solved the problem! I’m still curious how PyCharm and Spyder manage to solve the issue while only calling the environment python.exe directly.

For reference, here is the batch file that worked for me:

call C:\Users\myuser\Anaconda3\condabin\conda activate test_numpy
python -m example.py

Good to know that the Anaconda environment should be activated when possible.

Minor Edit: C:\Users\myuser\Anaconda3\condabin\conda activate test_numpy will work in the command line, but you need to use call C:\Users\myuser\Anaconda3\condabin\conda activate test_numpy if you are running a batch file.

See https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files

2reactions
mattipcommented, Mar 7, 2020

You should add something like

conda activate <myenv>

where you replace <myenv> with your environment name into your batch file. For more information, see the link in the comment above. So your batch file should be something like

conda activate <myenv>
python <script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to run .bat file with python code: ImportError
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was...
Read more >
How to run batch file by using python code?
The possible output is command line window opening with a command prompt. Operating system is windows 10. I am using this code. import...
Read more >
How to Run a Batch File from Python - Data to Fish
To start, here is a simple template that you can use to run a batch file from Python: import subprocess subprocess.call([r'path where the ......
Read more >
Troubleshooting — Anaconda documentation
If the Python command “import numpy” fails, the system is likely missing the libgomp system library. Cause¶. Most Power8 Linux distributions include libgomp, ......
Read more >
numpy.load — NumPy v1.24 Manual
Allow loading pickled object arrays stored in npy files. Reasons for disallowing pickles include security, as loading pickled data can execute arbitrary ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found