Python ImportError "cannot import name 'multiarray' - python

I'm trying to simply import numpy into a python script (called "MatPlotLib.py using PyCharm) and I'm receiving this odd error. It worked fine, but then I started messing around with Jupyter. I tried uninstalling and reinstalling Python, then a system restore, but nothing seems to be working. I think reinstalling numpy will do the trick, though I'm not sure how to do that.
I'm not sure what the error means by "a numpy git repo, so any help would be greatly appreciated. If you need any additional information please let me know. Find the full error below! :)
Thank you so much in advanced.
C:\ProgramData\Anaconda3\python.exe
C:/Users/Alex/PycharmProjects/2017_Research/Automation/MatPlotLib.py
Traceback (most recent call last): File
"C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\core__init__.py",
line 16, in
from . import multiarray ImportError: cannot import name 'multiarray'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:/Users/Alex/PycharmProjects/2017_Research/Automation/MatPlotLib.py",
line 1, in
import numpy File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy__init__.py",
line 142, in
from . import add_newdocs File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\add_newdocs.py",
line 13, in
from numpy.lib import add_newdoc File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\lib__init__.py",
line 8, in
from .type_check import * File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\lib\type_check.py",
line 11, in
import numpy.core.numeric as _nx File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\core__init__.py",
line 26, in
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: cannot import name 'multiarray'
Process finished with exit code 1

Related

Cannot import numpy library in Python 3.8.0

I'm attempting to load a numpy library into python 3.8.0 on Ubuntu.
from numpy import loadtxt
gives a very verbose error, without a solution:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray' from partially initialized module 'numpy.core' (most likely due to a circular import) (/usr/lib/python3/dist-packages/numpy/core/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3/dist-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: cannot import name 'multiarray' from partially initialized module 'numpy.core' (most likely due to a circular import) (/usr/lib/python3/dist-packages/numpy/core/__init__.py)
Based on advice that I saw on Python circular importing? I changed the import line to import all of numpy:
import numpy
but this gives the same error.
As the error suggests, I tried re-installing numpy with pip:
sudo pip install --upgrade --force-reinstall numpy
the same error happens with
sudo pip3 install --upgrade --force-reinstall numpy
which worked, and installed numpy-1.19.5. However, this didn't fix the import problem.
I tried implementing a solution from https://github.com/numpy/numpy/issues/9047 which involves setting
export PYTHONPATH=/usr/lib/python3/dist-packages/$PYTHONPATH in ~/.bashrc, but this failed as well.
How can I import numpy?
The problem was that pip and python were linked to different versions.
The solution was to install via sudo /usr/bin/python3.8 -m pip uninstall numpy and then sudo /usr/bin/python3.8 install numpy
After looking into circular imports for a bit, it looks like you might just be better off doing import numpy and altering your code accordingly rather than using the from syntax

Error importing numpy even though I installed it properly

I am using a module called investpy, and numpy is a dependency of it. I tried running pip install investpy, which installed all of the dependencies (or so it says). However, when I try running
import numpy
or
import investpy
, I am faced with this error:
Traceback (most recent call last):
File "C:\Users\kakor\OneDrive\Desktop\ML\numpy\__init__.py", line 124, in <module>
from numpy.__config__ import show as show_config
ModuleNotFoundError: No module named 'numpy.__config__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\kakor\OneDrive\Desktop\ML\stockscreener.py", line 1, in <module>
import numpy
File "C:\Users\kakor\OneDrive\Desktop\ML\numpy\__init__.py", line 129, in <module>
raise ImportError(msg)
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 interpreter from there.
I'm really confused as to why this is happening, because as far as I know, I correctly installed numpy. Furthermore, this is really weird because, if I go to the python directory in cmd and run import numpy, it works perfectly.
Any help would be greatly appreciated. Thank you!
Essentially numpy seems to complain that it isn't being imported from a standard path.
It looks like you installed numpy directly into your project directory under C:\Users\kakor\OneDrive\Desktop\ML\numpy You should remove that directory and try running
pip install numpy

Issue running python script via PyCharm but not Anaconda Prompt

When I run a script in Anaconda Prompt, it works fine.
When I try to run it via PyCharm, I get this error related to the import of pandas.
C:\ProgramData\Anaconda3\python.exe C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py
Traceback (most recent call last):
File "C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py", line 2, in <module>
import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Process finished with exit code 1
If I try to import numpy and run it via PyCharm I get:
C:\ProgramData\Anaconda3\python.exe C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py
Traceback (most recent call last):
File "C:\ProgramData\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/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py", line 2, in <module>
import numpy as np
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\ProgramData\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
Running the same script in Anaconda prompt...no problem
My run configuration in PyCharm uses the Anaconda python distribution?
It should be noted that I am not using envirnoments, just the base Anaconda installation. More worryingly I dont see ANY Conda options in the project settings in PyCharm which a lot of tutorials seem to allude to.
Seems like a problem with the path for your scripts. Are you sure You have included your scripts in the PATH variable? If so are you sure your libraries are downloading/installing in that path?

numpy in Python 3.6: Importing the multiarray numpy extension module failed

Can anyone help me with this error? I don't have any older versions of numpy, and i installed it using pip, i get 1.13.0 version of numpy and I'm working on Windows 10 OS. Any suggestions?
Traceback (most recent call last):
File "C:/Users/Asus/PycharmProjects/g/num.py", line 1, in <module>
import numpy
File "C:\Users\Asus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Users\Asus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Users\Asus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Users\Asus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Users\Asus\AppData\Local\Programs\Python\Python36-32\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 procedure could not be found.
You are, apparently, a victim of issue 9272. numpy is built against Python 3.6.1 but you're using Python 3.6.0.
Based on the discussion there, you should just upgrade to Python 3.6.1 to get it to work. It does seem like they will build on 3.6.0 too, though, follow that issue to keep track of that.

Blender python import error: DLL load failes (only when using blender)

the question is may be similar to this one, but did not solve my issue and also is somehow much stranger:
I got a strange problem, where when executing only my python file from command line:
>python main.py, everything works. But when using it with blender like this:
blender -b ..\test.blend --pyhton ..\main.py
i get this error (file paths are substituted with ..) :
Traceback (most recent call last):
File "\\...\Blender\2.78\python\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "...\main.py", line 4, in <module>
import numpy as np
File "\\...\Blender\2.78\python\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "\\...\Blender\2.78\python\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "\\...\Blender\2.78\python\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "\\...\Blender\2.78\python\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "\\...\Blender\2.78\python\lib\site-packages\numpy\core\__init__.py", line 24, 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.
AL lib: (EE) UpdateDeviceParams: Failed to set 44100hz, got 48000hz instead
my main.py looks like this:
#import bpy
import sys
import numpy
import h5py
...more imports...
if __name__ == "__main__":
logging.info("No error")
The story I told so far, is fact, when I run the blender and python from a HTCondor Windows node. Again, only the python file works fine, but when including blender the DLL error occurs.
Additionally I tested everything before on my local PC where both variations work without issues, using exactly the same files! (Everything is located on a NAS drive)
There must be some linkage to some python stuff on my pc. I only have the miniconda3 directory, which i completely removed so blender can use the bundled one.
Hopefully somebody can help me and please feel free to ask for stuff I failed to explain.
EDIT:
The multiarray module is located in the numpy.core folder with the name mutliarray.cp35-win_amd64.pyd, which makes no sense to me why the module is found on my local PC but not on the HTCondor windows node.
EDIT 2:
According to sampler's suggestions I tried the following:
1) I used getenv = True in the submission file to submit the locally working environment with the job. Result: Does not work either.
2) I cleared all environment variables except those needed for running correctly on my local pc. Clearence happend with this lines:
for i in os.environ:
os.environ[i] = ""
The only used variable is set:
os.environ["PATH"] = "\\\\[servername]\\conda\\Blender\\2.78\\python\\Library\\bin;"
without this line I get the same multiarray import error on my local pc.
These lines are executed in my main.py script but still does not change anything when running on the condor node.
Even stranger is the fact, that running only the python script on the condor node works perfektly fine, but just running it with blender (as shown in the first codeline of this post), results in the multiarray import error.

Categories

Resources