The title is misleading in the following sense. You do not want to import the module into IDLE. You want to import it into the python where your code is running. When starting IDLE, it is currently the same python that IDLE is running on. To find which python is running, the following should work anywhere on any recent python, directly or in the IDE:
import sys; print(sys.executable)
By running this in IDLE on my windows machine, I get
C:\Programs\Python36\pythonw.exe
(The suffix w is a Windows-specific binary option for running graphical programs without a blank console window. It should be omitted in the future.)
To import a module into a specific python, it must be installed for that particular python. The easiest way to do this is to run pip with this particular python in the console. For example, given the executable above:
C:\Programs\Python36> python -m pip install numpy
On * nix, you may first need to run python -m ensurepip to set the pip itself for this python.
About import pip; pip.main import pip; pip.main : pip is designed as a command-line utility that initializes, performs one function, and exits. main () is the intentionally undocumented internal implementation detail. The author of pip does not recommend using it, since it is for one call, followed by the exit of the program. Several calls will not work correctly if the internal data is not synchronized with the installed files.
source share