How do I use Numpy in Python IDLE?

Variants of this question have been asked, but the answers always start from scratch (i.e. from a numpy installation).

I already have numpy installed on my computer from an earlier time when I downloaded Anaconda.

If I try to install numpy again with pip install numpy

, I get a long error, for example, the end of which looks like

Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\imray~1\\appdata\\local\\temp\\pip_build_Imray\\numpy\\setu
p.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\imray~1\appd
ata\local\temp\pip-smduhf-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\imray~1\appdat
a\local\temp\pip_build_Imray\numpy
Storing debug log for failure in C:\Users\Imray\pip\pip.log

      

numpy works fine when I open cmd

from folder Anaconda

and command import numpy

. But it won't work with IDLE even if I navigate to the specified folder (via os.chdir('C:\Anaconda')

) and issue the same command.

How do I get numpy to work in IDLE?

+3


source to share


1 answer


First, you may already know that Anaconda comes with its free IDE, which is very similar to IDLE in many ways. It is known as Spyder and should be available to any terminal as: spyder

. You can stop reading at this point and use that.

But if you really want to use IDLE, you first need to track it down. It is associated with every Python distribution that you have installed on your system. For example, I have the IDLE version installed at the following location:

/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/idlelib/idle.pyw

      

If I run the Python distribution that this copy of IDLE belongs to, I cannot access NumPy because I have never installed it on that distribution:

python3
...
>>> import numpy as np
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'

      

I have NumPy installed in my version of Canopy Python though (Canopy is very similar to Anaconda).

python
...
>>> import numpy as np
>>>

      



A workaround I can do to get NumPy in the console is this:

python /usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/idlelib/idle.pyw

      

I am doing a Canopy distribution in Python, which has NumPy, and invoking a different Python distribution like any script. The IDLE console then opens and lets me import and use NumPy.

This is a bit of a workaround and I found it hit and miss. When I use Canopy Python to open IDLE belonging to yet another Python distribution (Python 2.7 installed via Homebrew), sometimes I get the following error when using the instruction print

:

Unknown object id: 'console'

      

So just be aware that you may face such problems.

+3


source







All Articles