I use Pydev and try to load numpy in my script. I installed Anaconda to be able to use it, following the Anaconda user guide concerning how to set it up as interpreter in Pydev.
I have tried installing Anaconda both with and without adding it to PATH (the recommended version is without). In both cases numpy shows up as an installed package in Pydev:
However, when I run my script I receive the following error:
File "Z:\Path\To\My\file.py", line 2, in <module>
import numpy as np
File "C:\Users\(username)\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\(username)\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 also noticed that in the manual from anaconda, in the shown picture a lot more library folders are added than what I am presented with. I couldn't find a list of those, though. Running numpy from the Anaconda prompt works fine.
Any ideas would be appreciated!
Related
I am trying to use NumPy in Python. I have just installed Anaconda Python 3.7, and that all seemed to go smoothly. However, I cannot import numpy(using the line import numpy). When I do, I get the following error:
C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) 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 "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
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.7 from "C:\Users\jsmith\anaconda3\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.
I can see it in the Enviorments tab of Anaconda Navigator, and when I try to use it in Eclipse(Pydev) it shows up under forced builtins. I took a look at my PYTHONPATH, and both my enviorment in Eclipse and my base python directory (jsmith/anaconda3) are in it. I have tried importing other libraries I see under forced builtins,and those work fine, yet numpy seems to be the only one with issues. Calling pip install numpy tells me it is already installed with version 1.18.1. I looked at this stack overflow page, and ran the first command in the answer(conda create -n test numpy python=3.7 --no-default-packages) in anaconda prompt. This worked, and then I realized the test was specific to the question, and tried base instead, and got this error:
CondaValueError: The target prefix is the base prefix. Aborting.
However calling conda activate base did nothing.
As mentioned in the comments by #cel uninstalling and reinstalling numpy using pip uninstall numpy and pip install numpy made it work.
I better way is to
import os
import sys
os.path.dirname(sys.executable)
This will give you the path to your environment. Put the path into the settings for python
Open the Anaconda Prompt:
Then, you have to go to the Conda Environment that you want to use in PowerBI. Am having an environment 'temp', so I activate it first in the 'Anaconda Prompt':
(base) C:\Users\ashish>conda activate temp
Then I go to the directory having the "PowerBI" executable file in the installation folder:
(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"
Then, I launch PowerBI from the Prompt:
(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe
This fixes the NumPy error you are getting. If you want any other package to use with PowerBI, install that package in the respective "Conda Environment" (in my case it is "temp").
Make sure the Python home directory (Anaconda3) has been added to the 'Power BI Desktop' global options in the Python scripting section too.
I am trying to run a script which involves numpy through the terminal on WinSCP, but whenever I do, I get the following error:
import gensim
File "/data/work/worker/gensim/init.py", line 5, in
from gensim import parsing, corpora, matutils, interfaces, models, similarities, summarization, utils # noqa:F401
File "/data/work/worker/gensim/parsing/init.py", line 4, in
from .preprocessing import (remove_stopwords, strip_punctuation, strip_punctuation2, # noqa:F401
File "/data/work/worker/gensim/parsing/preprocessing.py", line 42, in
from gensim import utils
File "/data/work/worker/gensim/utils.py", line 38, in
import numpy as np
File "/data/work/worker/numpy/init.py", line 142, in
from . import core
File "/data/work/worker/numpy/core/init.py", line 50, in
raise ImportError(msg)
ImportError:
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.
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: Python2.7 from "/usr/bin/python"
The NumPy version is: "1.18.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named _multiarray_umath>
I suspect that the issue is that the version of Python being quoted here is outdated; however, after having done some searching, I cannot find any literature on how to update Python on WinSCP. I have Python 3.8 installed on my machine, and I have tried moving the installer and the .exe file into the WinSCP directory to no avail. Is there any way to update python directly in the terminal? Alternately, is this issue actually nothing to do with a stale version of Python at all?
I'm trying to run a Python script from the Windows shell, but when I do
python path\to\file\script.py
I get an error "DLL load failed: The specified module could not be found" and it traces back to the line where I import numpy.
C:\Users\Admin>python path\to\file\script.py
Traceback (most recent call last):
File "path\to\file\script.py", line 8, in <module>
import numpy as np
File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\Admin\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.
The weird part is that when I run it in an editor like Spyder, numpy imports just fine. Can someone help me?
Thanks
It's fixed Anaconda path issue. Check your %PATH% if it's correctly defined.
Source: https://github.com/numpy/numpy/issues/12957
This is a common problem when installing python packages, mainly in windows.
Numpy and other packages have bindings to C++ code that require some special dependencies.
Rather than trying to get the dependencies exactly right for compiling the package, you can use a precompiled "wheel" file from one of several sources.
I use Chris Gholke's site
download the .whl file and install using
pip install directory/path/package.whl
edit: and as a note, the python environment you access from powershell or cmd is different from the anaconda environment in spyder. One of the differences between conda and pip is that conda installed precompiled packages while pip does not.
I solved my issues with Numpy DLL load issues by replacing Anaconda3 with WinPython.
In Windows, I created a Conda virtual environment with the command
conda create -n test python=2.7 pandas scipy matplotlib numpy
Once it is created, I activated the virtual environment and went into a python interpreter. When trying to import numpy, I get the following error:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\envs\test\lib\site-packages\numpy\__init__.py", line 180, in <module>
from . import add_newdocs
File "C:\Anaconda3\envs\test\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda3\envs\test\lib\site-packages\numpy\lib\__init__.py", line 8,
in <module>
from .type_check import *
File "C:\Anaconda3\envs\test\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda3\envs\test\lib\site-packages\numpy\core\__init__.py", line 14, in <module>
from . import multiarray
ImportError: DLL load failed: The specified module could not be found.
Any ideas what is going on here? Thanks!
Uninstall and install numpy again.
pip uninstall numpy
pip install numpy
Then try import again, it should work. That is what I did
Unlike #Rafael, for me, libiomp5md.dll wasn't the issue. I installed Dependency Walker to investigate what was going on. Even though the dll versions were different, but Dependency Walker said it was okay.
What was wrong though, was that mkl_intel_thread.dll had warnings (red icon). If you're using Win 8++, ignore the api-win and ext-ms issues as Dependency Walker wasn't updated for new Windows versions and doesn't recognise Windows new APIs.
My solution is to copy all mkl_*.dlls from the former to the latter:
\Anaconda2\Library\bin
\Anaconda2\Lib\site-packages\numpy\core
I was able to import numpy and sklearn after that.
It seems the proper way to fix this is to do:
conda install msvc_runtime
If you are in a virtual environment, add this package there.
For my case, I have also the import numpy DLL error in anaconda3, and Decrayer (Nov 28) provided the best solution: I had the same error except for Anaconda3: just added the path \Anaconda3\Library\bin to your Windows 10 path variable and then it worked.
I have been trying to install anaconda3.7.1 or 3.7.0 without luck, going to full length of restarting the PC after the key steps to make sure the DLL is no longer in use in memory. Ultimately, thanks to decrayer, now numpy works for me!
For me this was solved by adding the following paths to my system path variable.
C:\Users\UserName\Anaconda3\
C:\Users\UserName\Anaconda3\bin
C:\Users\UserName\Anaconda3\Scripts
C:\Users\UserName\Anaconda3\Library\mingw-w64\bin (not strictly necessary)
C:\Users\UserName\Anaconda3\Library\bin
Before adding them explicitly in the system path variable, you can perform a test by adding these paths temporarily:
base_path = r"C:\Users\UserName\Anaconda3"
path = os.pathsep.join([os.path.join(base_path, i) for i in [r"", r"bin", r"Scripts", r"Library\mingw-w64\bin", r"Library\bin"]])
os.environ["PATH"]+=os.pathsep+path
Thanks to this post on PyCharm support.
For the record, I had the same error here (Python 3.5 64-bit on Windows 10), and this page helped me find the solution. The problem was a conflict with libiomp5md.dll, which existed on two locations:
C:\Windows\System32\libiomp5md.dll
C:\Anaconda3\Library\bin\libiomp5md.dll
Python was trying to use the version in System32 folder, which was an old version. I removed it (renamed) and now it uses the correct version, on Anaconda3 folder, and now I can import numpy without the import error.
When I try to import the slycot module in spyder (version 2.2), I get the following error:
RuntimeError: module compiled against API version 7 but this version of numpy is 6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/__init__.py",
line 4, in <module>
from slycot.analysis import ab01nd,ab05md,ab05nd,ab07nd,ab08nd, ab09ad
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/analysis.py",
line 21, in <module>
from slycot import _wrapper
ImportError: numpy.core.multiarray failed to import
Now, when I import slycot in the python shell through my terminal, there are no problems at all. I think the reason why there are no problems through the terminal, is that I recently installed numpy 1.7.1. Spyder on the other hand still uses numpy 1.6.2.,hence the error.
I tried to change the numpy version in spyder, but so far that didn't work.
When I change the numpy(6) folder in my spyder lib with the recently installed numpy(7), I get the following error (in spyder):
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
What is the best way to solve this error?
Thanks in advance.
(Spyder dev here) At the moment it's not possible for the user to install anything inside the app. I guess you moved your slycot module from another interpreter to our App (because of the numpy error you mention).
The right way to use different modules not present in the app, is to change the path of your interpreter in:
Tools > Preferences > Console > Advanced settings > Python executable
If you installed slycot using your system Python, you have to select
/usr/bin/python