You have to install numpy from Command Prompt, not IDLE.
Follow these steps on Windows:
- Press the Windows key on your keyboard.
- Type CMD and open Command Prompt. A black terminal should open up.
- Type 'pip install numpy' and hit enter.
- It should start the installation. After you see the "Successfully Installed" message, go back to your IDLE and try importing numpy, it should work.
NOTE: In case you get a message saying "pip" is not recognized, refer to: https://stackoverflow.com/a/56678271/13699502
Answer from Eshaan Gupta on Stack OverflowYou have to install numpy from Command Prompt, not IDLE.
Follow these steps on Windows:
- Press the Windows key on your keyboard.
- Type CMD and open Command Prompt. A black terminal should open up.
- Type 'pip install numpy' and hit enter.
- It should start the installation. After you see the "Successfully Installed" message, go back to your IDLE and try importing numpy, it should work.
NOTE: In case you get a message saying "pip" is not recognized, refer to: https://stackoverflow.com/a/56678271/13699502
You write pip install numpy in the command prompt (CMD) if you are on Windows.
And, most of the times py -m pip install numpy helps more on Windows.
On macOS/Unix, you can use python -m pip install numpy in terminal/console.
python - How to import/open numpy module to IDLE - Stack Overflow
How to install numpy on IDLE opposed to terminal?
No module name numpy in IDLE Shell but works in CMD
Using numpy in IDLE or PyCharm
If anyone gets here because they're looking for a similar answer, go here.
More on reddit.comVideos
The title is misleading in the following sense. You do not want to import a module to IDLE. You want to import it to the python that is running your code. When running IDLE, this currently is the same python running IDLE. To find which python is running, the following should work anywhere on any recent python, either directly or in an IDE:
import sys; print(sys.executable)
Running this in IDLE on my Windows machine, I get
C:\Programs\Python36\pythonw.exe
(The w suffix is a Windows-specific variant binary for running GUI programs without an empty console window popping up. It should be omitted in what follows.)
To import a module to a particular python, it must be installed for that particular python. The easiest way to do that is to run pip with that particular python in a console. For instance, given the executable above:
C:\Programs\Python36> python -m pip install numpy
On *nix, one may have to first run, I believe, python -m ensurepip to install pip itself for that python.
About import pip; pip.main: pip is designed as a command line utility that initializes, performs one function, and exits. main() is an intentionally undocumented internal implementation detail. The author of pip discourages its use as it is designed for one call followed by program exit. Multiple calls will not work right when internal data get out of sync with installed files.
To install packages without affecting anaconda's configuration you can use pip from within IDLE:
import pip
pip.main(["install","numpy"])
In later versions this is no longer directly exposed, since doing this in production code is bad. but you can still import the internals to install a module.
from pip._internal.main import main as pip_main
pip_main(["install","numpy"])
Although because IDLE can be a little slow with refresh rate (at least it is on my mac) it can be a great speed boost to hide the output until the end:
import sys
import pip
import io
stdout_real = sys.stdout
sys.stdout = io.StringIO()
try:
pip.main(["install","kfksnaf"])
finally:
stdout_real.write(sys.stdout.getvalue())
sys.stdout = stdout_real
note that this means that all standard output will be displayed after the error text which might be confusing if something goes wrong so do try it normally first and only do this if it lags badly.
On the other hand, it seems like anaconda has commandeered a lot of the functionalities of the python installed from python.org, to reduce it's impact on your machine you should take a look at Use Default Python Rather than Anaconda Installation When Called from the Terminal although this might then break functionalities of anaconda which may then in turn make it difficult to switch back if you want to do so.
My Mac OS terminal is running 2.7.10 and my IDLE shell is 3.4.3. I want to get numpy working on my IDLE shell, but I don't understand how to link it correctly. I have homebrew and I ran pip install numpy which I verified installed correctly but only on the terminal Python, it's not recognized by the IDLE. Do i have to change some paths around or something? How do I get numpy on IDLE?
I installed numpy on a windows 10 machine with pip in the Python directory, when I run my program in the shell it says tha there is a "ModuleNotFoundError: No module named 'numpy'" But when I run the script in Command Prompt numpy has been installed. Do i need to install numpy to the folder where my script is or something?
[SOLVED] Hey,
I just wrote a script for some research I'm doing using numpy, but I am only able to execute while running python in Terminal. Whenever I try executing in pycharm or IDLE, I get the following error when trying to execute:
import numpy as np
ImportError: No module named numpy
I've downloaded numpy, but I don't know how to install it such that it will be importable in these IDE's.
A coworker sent me a Python file that uses numpy, so when I tried to run it, I got the error "No module named 'numpy'". So I looked up numpy, and it said in order to get that, I needed either conda or pip. so I looked up how to get conda, and it said I had to first download Anaconda. So I download Anaconda. I look in there and it would seem to me that both conda and numpy are already in there: Under Environments, both conda and numpy are listed as installed. But then I went back and tried to run the program again, and I got the same error. What else do I need to do to access numpy?
Also, idk if this matters, but I'm running Python on IDLE. Do I need to use a different IDE?