9

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?

Andrew J Winkler
  • 465
  • 1
  • 4
  • 14
  • Maybe run a package update first? So you can do "conda update numpy" for just numpy or "conda update anaconda" for the whole distro. – davo36 May 08 '16 at 03:58
  • tried both of your suggestions. I'm still getting the same error – Andrew J Winkler May 08 '16 at 04:10
  • So what about from the Python console? – davo36 May 08 '16 at 05:17
  • via the python 3.4 command line importing numpy works, also running a python 3.4 script in pycharm works too.. it's just in anaconda that it doesn't – Andrew J Winkler May 09 '16 at 04:55
  • 1
    Ah ok, do you have several python environments? Like do you have 2.7 and 3.4 installed on the same machine? – davo36 May 09 '16 at 05:02
  • yes. when opening up pycharm I have 3 options for my interpreter '3.4.4 at C:\Python34\python.exe', '2.7.11 (C:\Anaconda2\python.exe)', and 'C:\Anaconda3\python.exe' – Andrew J Winkler May 09 '16 at 05:18
  • Well I'm just guessing, but I'd say you are having problems because of these multiple installs. It thinks it's possible to do, see here: http://stackoverflow.com/questions/3809314/how-to-install-both-python-2-x-and-python-3-x-in-windows-7 But you're also using Jupyter, so I have no idea how that would decide which interpreter to use... Good luck man. – davo36 May 09 '16 at 05:23
  • thanks for the help. I think I'm just gonna uninstall all instances and install anaconda on 2.7... it seems every package I have will run on that version of python as a standard – Andrew J Winkler May 09 '16 at 06:59
  • I fixed it. In case you're curious, my method is described below – Andrew J Winkler May 09 '16 at 08:16

3 Answers3

16

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.

keag
  • 299
  • 2
  • 15
Andrew J Winkler
  • 465
  • 1
  • 4
  • 14
  • 1
    Just wanted to say thanks, I did pretty much what you did: I uninstalled EVERY python distro on my computer including anaconda and then reinstalled anaconda, and now it appears fine (no more import errors). Some value added: presumably, conda should manage all the different python environment/versions now for you! – information_interchange Mar 08 '18 at 21:46
8

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.

Tshilidzi Mudau
  • 7,373
  • 6
  • 36
  • 49
0

try activating you base conda environment before starting jupyter.

>activate root
>jupyter notebook
mark jay
  • 1,256
  • 14
  • 23
  • ImportError: Error importing numpy: you should not try to import numpy from its source directory – CS QGB Aug 25 '22 at 03:16