How do I use Numpy in Python IDLE?

12,628

Firstly, you might already know that Anaconda comes with its own free IDE, very similar to IDLE in many respects. It's known as Spyder, and should be accessible in any terminal as: spyder. You could stop reading at this point and use that.

But if you really want to use IDLE, you'll need to track it down first. It's bundled with each distribution of Python that you have installed on your system. For example, I have a version of IDLE 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 can't access NumPy, because I've never installed it in that distribution:

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

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

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

The 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'm executing the Canopy distribution of Python, which does have NumPy installed, and calling the other Python distribution's IDLE as you would any script. Then the IDLE console pops up and does allow me to import and use NumPy.

This is bit of a workaround and I have found it to be hit-and-miss. When I use Canopy's Python to open the IDLE belonging to yet another distribution of Python (Python 2.7 installed through Homebrew), I sometimes get the following error when using the print statement:

Unknown object id: 'console'

So just be aware that you could run into issues like that.

Share:
12,628
CodyBugstein
Author by

CodyBugstein

Aspiring computer nerd.

Updated on June 04, 2022

Comments

  • CodyBugstein
    CodyBugstein almost 2 years

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

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

    If I try to install numpy again using pip install numpy, I get a long error like, 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 inside the Anaconda folder and command import numpy. But it won't work from IDLE even if I navigate to said folder (via os.chdir('C:\Anaconda')) and issue the same command.

    How do I get numpy to work in IDLE?

  • CodyBugstein
    CodyBugstein almost 10 years
    Cool! I hadn't known about spyder. I've got it open now and it looks awesome. Thanks!
  • Raydot
    Raydot about 7 years
    Same here. Thanks!