Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Numpy results in error even though Anaconda says it's installed?

I signed up for a statistics udemy course which uses jupyter running the stock numpy package out of anaconda.

Numpy is working when I run python 3.4.4 in pycharm, but it will not work in either anaconda2 nor anaconda3.. this makes no sense because numpy comes stock as part of the anaconda library.

When I try importing numpy in jupyter, running a local instance of a python 2 script, I get this: screenshot of jupyter error message

Thinking I could sidestep the error using a IDE, I tried pycharm and I got this:

sreenshot of pycharm error message

Numpy is part of the anaconda default library which I'm running, so I checked and made sure the numpy package was there via the Anaconda Prompt using 'conda list'...

screenshot of the anaconda prompt showing all packages

Why won't it import successfully?

Before I uninstall and reinstall everything, does anyone have any ideas?

like image 684
Andrew J Winkler Avatar asked May 08 '16 03:05

Andrew J Winkler


People also ask

Why is NumPy not importing?

Python Import Numpy Not Working Python import numpy is not working that means eithers the module is not installed or the module is corrupted. To fix the corrupted module, uninstall it first then reinstall it.

Is NumPy automatically installed with Anaconda?

If you installed the Anaconda distribution of Python, NumPy comes pre-installed and no further installation steps are necessary. If you use a version of Python from python.org or a version of Python that came with your operating system, the Anaconda Prompt and conda or pip can be used to install NumPy.

How do I import NumPy into Anaconda prompt?

Diagnosis steps: 1) activate a conda environment (Anaconda Prompt on Start menu); 2) type conda list numpy (should return a version); 3) type python , 4) at python's >>> prompt, type import numpy as np . Likely you will get an error somewhere, and that will help identify what needs to be done to fix the error.

How do I know if NumPy is installed on Anaconda?

Make sure you are using the Anaconda prompt, as the conda command only works in an Anaconda environment, and type conda list numpy . The result will show the version of numpy and associated packages.

Why do I get import error when trying to import NumPy?

When I'm running scripts on Spyder, or just trying to import numpy on Anaconda Prompt this error message appears: ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy.

Where is NumPy installed in Anaconda?

The numpy package is actually installed in the pkgs folder inside the Anaconda folder in my computer. Should I be running the .ipynb file from a specific folder in order to Anaconda to be able to import numpy? I should not that when importing numpy in Spyder it does work. I am confused about why is this happening. pythonnumpy Share

How to import NumPy and pandas in Python?

type pythonhit enter the python terminal starts >>> (venv) bash-3.2$ python Python 3.7.0 (default, Jun 29 2018, 20:14:27) [Clang 9.0.0 (clang-900.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> import pandas as pd

Why can't I import Multiarray NumPy extension module?

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'.


2 Answers

Yayyyy. I figured it out. So I had several different python versions before I was running python through anaconda/jupyter. As a result, the tethering in-between the additional package libraries to the version of python running was shifty. For example, I may have had numpy working configured to 3.4 but not 2.7..

anyways, to break down the steps I took, I uninstalled all instances of python (both anaconda and normal versions). Then I deleted the old 3.4 libraries from my C drive. Then I installed anaconda 2.7.11 again, tested importing numpy and got the same error. Then I thought to myself, what if the packages are installed separate from the python library and their configuration didn't get reset via the reinstall.. so via the anaconda prompt I typed:

pip uninstall numpy

which removed the package I was having trouble with. and then :

pip install numpy

which downloaded and reset a whole new instance of the package. Then I tested importing numpy in both the anaconda prompt and jupyter = both worked.

I'm very happy that this ended up working out as I can continue on as planned. For anyone else who experiences a similar problem, I would try uninstalling, then reinstalling the problem causing package via pip commands - this step seemed to have the most impact on fixing the problem. Then if that doesn't work proceed to uninstall and reinstall the environments in intervals.

like image 180
Andrew J Winkler Avatar answered Nov 15 '22 20:11

Andrew J Winkler


You can try using the following command:

pip install numpy --upgrade

This will uninstall old installed version of numpy and install a new version. This command solved my issue.

like image 39
Mayuresh Dhawan Avatar answered Nov 15 '22 21:11

Mayuresh Dhawan