Reputation: 1103
I am using the Anaconda distribution with Python 3.7. Among the packages installed, I have numpy, pandas, etc. In PyCharm IDE, I have set the Project Interpreter to be the path to the python.exe installed with Anaconda: C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\python.exe
However, when I try running a simple python script:
import numpy as np
print(np.pi)
I get an error:
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
See the full error message below:
----------------------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
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 "C:/Users/my_user_name/Documents/TestMyApps/simpletest.py", line 1, in <module>
import numpy as np
File "C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\my_user_name\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
Process finished with exit code 1
----------------------------------------------------------------------------------
I have tried uninstalling and reinstalling numpy using Anaconda Prompt with: conda uninstall numpy, and then: conda install numpy [I now have numpy 1.15.4]. The re-install seem 'successful' (at least according to Anaconda Prompt), but, I keep getting an error in PyCharm.
The strange part, is when I directly go into Anaconda Prompt, and type:
python
import numpy as np
print(np.pi)
I do not get any error, and I am able to see the correct result printed out. At first, I thought that perhaps, when using PyCharm, I am somehow pointing to a different executable, but I checked in both Anaconda Prompt and Python Console of Pycharm, using:
sys.executable
and they both show the same path:
'C:\\Users\\my_user_name\\AppData\\Local\\Continuum\\anaconda3\\python.exe'
Note that in PyCharm, when I try running a script where I am not importing any library, or when the library imported are just like sys or os, the scripts run fine. However, when I try running any other script that involves importing a library that somehow depends on numpy, it fails as well (i.e. scripts where I import pandas, etc.) Those same scripts work fine in Anaconda Prompt.
I am at a loss here, any help would be very appreciated!
Upvotes: 66
Views: 154988
Reputation: 348
For Anaconda 3 on windows: use something to search for the Anaconda3 folder.
To use the cmd tool:
Change to the root of a drive: (Say C:) like cd /d c:
and search like so
C:>
dir Anaconda3\Library\bin /AD /s /b
repeat for each drive until you get a hit.
D:>
dir Anaconda3\Library\bin /AD /s /b
D:\Anaconda3\Library\bin\1033
knowing this add D:\Anaconda3\Library\bin
to the PATH user variable
(we dont want the 1033)
Then restarted the cmd shell. It should now operate
tensorboard --logdir results
TensorBoard 1.14.0 at http://here-x:6006/ (Press CTRL+C to quit)
Upvotes: 0
Reputation: 540
All I had to do was to force reinstall numpy
.
A regular uninstall (pip uninstall numpy
) would have removed all the high level packages dependent on Numpy.
I used pip install --upgrade --force-reinstall numpy
for reinstalling Numpy forcefully.
Upvotes: 3
Reputation: 5156
I ran into the problem lately with Pycharm 2021.3.1 .
My solution was simply to remove the interpreter from pycharm's "python interpreters" list, and to re-add it again. I then waited for the skeletons, indexes, etc. to be built by pycharm, and re-run the same run configuration.
Surprisingly, everything was working again !
I had to do it twice in two days though, it does not seem very stable. Apparently PyCharm has some issues in setting the PATH correctly for conda envs.
Maybe it will be fixed soon, I'll try the updates
See https://youtrack.jetbrains.com/issue/PY-31896#focus=Comments-27-5858759.0-0
Upvotes: 3
Reputation: 29
I just faced the same issue and found the top solution above useful (https://stackoverflow.com/a/54131905/3645664).
In particular, I added following path at the user profile level and NumPy started working normal:
C:\Anaconda3\Library\bin\
Upvotes: 2
Reputation: 1179
Caught same error, found this thread, but nothing help. I do not have anaconda, but use numpy in windows service using win32serviceutil. NB, problem does not occured in cmd - only into service.
Solution was to install actual VC++ redistributable (!!!) (Microsoft Visual C++ 2015 x64 in my environment). Nothing points on this library.
Hope this answer will help anyone.
Upvotes: 0
Reputation: 313
I encountered the problem in my conda package manager and jupyter notebook on Windows 10 system. Adding CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
solved the problem.
Two-step solution.
(1) Find where your environment config of ipykernel is:
jupyter kernelspec list
In my case the path was C:\ProgramData\jupyter\kernels\myenv
(2) Add "env": {"CONDA_DLL_SEARCH_MODIFICATION_ENABLE":"1"}
in kernel.json
file in the path. For instance, this is my kernel.json
after editing (don't forget to add comma to preserve correct json format):
{
"argv": [
"C:\\Users\\tsund\\miniconda3\\envs\\myenv\\python.exe",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "myenv",
"language": "python",
"metadata": {
"debugger": true
},
"env": {"CONDA_DLL_SEARCH_MODIFICATION_ENABLE":"1"}
}
Upvotes: 0
Reputation: 23
I found my issue was in how VSCode was setup. Even though I was in a virtual environment, it was not running the version I installed. If you are using a virtual enviroment, check the path of the python.exe
that it is using to run your code. I.E. C:/Users/user_name/Anaconda3/python.exe
vs c:/Users/user_name/Documents/pythonTesting/appName/Scripts/python.exe
Running pip list
showed the correct version, but running the script gave an error with a different version.
Eventually I noticed that VSCode was using the default Conda instead of the python.exe that was in my virtual environment.
To fix this you need you need to press CTRL+SHIFT+P
(on Windows anyway) and choose interpreter, find your virtual environments Scripts folder, and point it to the python.exe within.
Bingo.
Upvotes: 0
Reputation: 3098
May be a bit of a braindead answer but I had this happen to me in PyCharm because I tried to run my script before it finished "discovering binary modules". And then even after completing this process, I still couldn't run the code without getting this error.
Simply restarting PyCharm fixed it.
Upvotes: 0
Reputation: 31
I had this issue with numpy 1.20.1 and the following:
I could import numpy using the Anaconda command prompt but not with Visual Studio Code.
I resolved it by uninstalling and then reinstalling numpy then it worked.
Upvotes: 1
Reputation: 21
I tried to include the PATH but it didn't work. So I tried reinstalling Anaconda and realized that the previous time I installed it, I had not enabled the option "Add Anaconda3 to my PATH environment variable". I enabled that and installed and it worked perfectly.
Upvotes: 2
Reputation: 1
Uninstalling and reinstalling numpy worked for me.
pip uninstall numpy
pip install numpy
Upvotes: -2
Reputation: 33
Adding Anaconda to System PATH didn't work for me, but uninstalling and reinstalling did.
Upvotes: 1
Reputation: 41
Adding C:\ProgramData\Anaconda3\envs\tf-gpu\Library\bin
to System Path also worked for me.
Upvotes: 4
Reputation: 49
Just try uninstall and Reinstalling
pip uninstall numpy
and
pip install numpy
or
pip3 install numpy
Upvotes: 2
Reputation: 299
Same Solution here as DanielTuzes's solution A, but I write it down here more clearly:
If you are using VS Code + Windows + Anaconda you should :
- Open the command palette (Control-Shift-P)
- search for Terminal: Select Default Profile
- select: Command Prompt
That did the trick for me !
That's because the PowerShell in VS Code is not integrated by default with anaconda prompt, this latter using CMD and not the PowerShell.
Upvotes: 1
Reputation: 432
play the below GIF and follow as given.
source - JetBrain
It worked for me..
Upvotes: 0
Reputation: 2744
In my case, conda didn't place the packages where my IDE (VS Code) or pytest expected them. Although I was able to call pytest within the environment, VS Code was unable [1] to debug the pytest modules. I came up with 2 solutions.
code
to open VS Code)A thread on VS Code's python extension tells that this is an issue on conda's side.
[1]: I was able to run pytest manually, from an activated environment, but pytest, started from VS Code's debugger somehow was not aware of numpy's location. The error message I've got after starting a debug session on a pytest function was the following:
_______________________ ERROR collecting test_pytest.py _______________________
ImportError while importing test module 'c:\Users\userFolder\test_pytest.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\miniconda3\lib\site-packages\numpy\core\__init__.py:22: in <module>
from . import multiarray
..\..\miniconda3\lib\site-packages\numpy\core\multiarray.py:12: in <module>
from . import overrides
..\..\miniconda3\lib\site-packages\numpy\core\overrides.py:7: in <module>
from numpy.core._multiarray_umath import (
E ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
..\..\miniconda3\lib\importlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test_pytest.py:2: in <module>
import numpy
..\..\miniconda3\lib\site-packages\numpy\__init__.py:140: in <module>
from . import core
..\..\miniconda3\lib\site-packages\numpy\core\__init__.py:48: in <module>
raise ImportError(msg)
E ImportError:
E
E IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
E
E Importing the numpy C-extensions failed. This error can happen for
E many reasons, often due to issues with your setup or how NumPy was
E installed.
E
E We have compiled some common reasons and troubleshooting tips at:
E
E https://numpy.org/devdocs/user/troubleshooting-importerror.html
E
E Please note and check the following:
E
E * The Python version is: Python3.8 from "C:\Users\userFolder\miniconda3\python.exe"
E * The NumPy version is: "1.19.2"
E
E and make sure that they are the versions you expect.
E Please carefully study the documentation linked above for further help.
E
E Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
Upvotes: 13
Reputation: 571
The problem is that there are two different versions of numpy. what you can do is uninstall the numpy lib. I think you must uninstall numpy two times. because two different numpy versions.
pip uninstall numpy
pip uninstall numpy
Upvotes: 1
Reputation: 79
Even I was running the python file on command prompt, but the python.exe was from Anaconda. so when you run any python file you get,
Warning: This Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load. To activate this environment please see https://conda.io/activation.
you need to activate the environment by using this command
conda init cmd.exe
conda activate
you see the command window as below, with base env
(base) C:\Users\yash\Documents\pycharm_project\venv>
Doing this I resolved this error
ImportError: numpy.core.multiarray failed to import Traceback (most recent call last): File "opencv_p1.py", line 2, in import cv2 File "E:\Anaconda3\lib\site-packages\cv2__init__.py", line 3, in from .cv2 import * ImportError: numpy.core.multiarray failed to import
In case you want to deactivate the conda use
conda deactivate
Please follow this link in case you have any doubt https://conda.io/activation
Upvotes: 0
Reputation: 129
Get the os environment path like:
import os
os.environ['PATH']
Now, add this path to the environment variable PATH
in pycharm debugger/console output. It works.
Upvotes: 5
Reputation: 697
Edit your System Environment Variable "PATH’ (refer steps here) by adding below given path.
Note: Follow this step if you already have numpy installed.
If using anaconda:
C:\Users\<username>\AppData\Local\Continuum\Anaconda<version>\Library\bin\
If using independent python interpreter:
C:\Users\<username>\AppData\Roaming\Python\Python<version>\Library\bin
Upvotes: 16
Reputation: 402
For PyCharm users wanting an easy fix, this issue is fixed in PyCharm 2019.2.
Upvotes: 5
Reputation: 1103
I have actually figured out the solution. I had initially edited my System Environment Variable ‘PATH’ by adding the path to the Scripts folder in my Python executable directory. Turns out, this was NOT enough...
I had to add more paths to it, and that magically did the trick.
See below the paths I added for the System Environment Variable PATH:
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Scripts\
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Library\
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Library\bin\
C:\Users\<myusername>\AppData\Local\Continuum\Anaconda3\Library\mingw-w64\bin\
Now, I am not sure exactly which one path among these 4 my System was really looking for in particular. However, adding this combination sure did work for me 😊
Upvotes: 112