Skip to main content


Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7


Hello there,

By this topic you must have got the Idea what I am taking about....

But for those who are "N-E-W" to python... well "PIP" is actually a command line where you can install Add-ons to your python program. We don't call it Add-ons we call it "MODULES".

There are various type of modules that could make your coding much faster and that means writing less code getting better output. i.e. Example. Suppose you have 10 lines of code can cook food. The module can do the same with 1 line of code. So, you get the basic idea.

OK that was lame but that's the best way I could think of putting it right now. (For the Newbies to understand. For pro's don't get judgemental.)

#Little bit about PIP
OK, now to install a module we need to use PIP. Correct? And to do so we have to open command prompt that is CMD that is DOS that is the small black screen from the 80s. Something like this one.

And here we type:- pip install "Bla bla module". Well to me its kind of old fashion and boring.

So, I found a way to do it right inside Python IDLE and no need to use command prompt again and again.

So... coming back to whats this post is all about....

Here is my code:-

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
######Dev:- Joel Dcosta######################################
######Telegram:- https://t.me/pysnake
######FB Group:- https://www.facebook.com/groups/pythonsnake/
######FB Page:- https://www.facebook.com/PythonProgrammers/
#############################################################

import os
import sys

def restart_program():
    python = sys.executable
    os.execl(python, python, * sys.argv)
# For Python 2.7+ to 3.4+ users use python 
# For python 3.7+ users use python3 

# I am using python3.7+
pip_install = "python3 -m pip install "
#pip_install = "python -m pip install " #For python2+

install_input = input("What Module you want to install?:- ")

print(pip_install + install_input)
os.system(pip_install+install_input)
print("Done")
restart_program()

Type this code or just copy paste it into your blank python IDE what ever you are using and save it as "mypip.py" inside the python folder where it is installed.

#Saving mypip.py
Assuming your python is installed inside...
C:/user/python/python37 so save it inside python37 folder.
Or if your path is not in C drive then maybe its in appdata folder.

#Finding Path
- So on in CMD type..
  type - RUN [Enter]
  type - %appdata% [Enter]

- On your Address Bar you will see you landed on C:\Users\ADC\AppData\Roaming
Replace Roaming  to  Local
Just change it to C:\Users\ADC\AppData\Local
Now look for python folder. And save it there.

#What this code does?...
With this code you can install pip modules right inside from your Python IDLE (Pyton GUI). And you do not have to open CMD/Command Prompt/DOS again and again.

All you have to do is open Python GUI and type the following code.
i.e. import mypip

It will ask you "What Module you want to install?:- "
just type the name of the module and the installation will be done with an output confirmation "Done".

The restart_program( ) function will restart the python shell so you can install more modules later.

But if you don't want to restart the the python shell just comment out by placing "#"

i.e.  #restart_program( ) inside mypip.py script.

Demo inside Python IDLE:- installing a module named - "sms"

1
2
3
4
5
6
7
8
9
Python 3.7.0(v3.7.0) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import mypip
What Module you want to install?:- sms
python3 -m pip install sms
Done

>>> ================================ RESTART ================================
>>> 


#Inside pip in depth
But if you want to get more in depth into PIP then type the following command in CMD.

i.e. python -h pip

and you will get the output...
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-b     : issue warnings about str(bytes_instance), str(bytearray_instance)
         and comparing bytes/bytearray with str. (-bb: issue errors)
-B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d     : debug output from parser; also PYTHONDEBUG=x
-E     : ignore PYTHON* environment variables (such as PYTHONPATH)
-h     : print this help message and exit (also --help)
-i     : inspect interactively after running script; forces a prompt even
         if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I     : isolate Python from the user's environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O     : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO    : remove doc-strings in addition to the -O optimizations
-q     : don't print version and copyright messages on interactive startup
-s     : don't add user site directory to sys.path; also PYTHONNOUSERSITE
-S     : don't imply 'import site' on initialization
-u     : unbuffered binary stdout and stderr, stdin always buffered;
         also PYTHONUNBUFFERED=x
         see man page for details on internal buffering relating to '-u'
-v     : verbose (trace import statements); also PYTHONVERBOSE=x
         can be supplied multiple times to increase verbosity
-V     : print the Python version number and exit (also --version)
-W arg : warning control; arg is action:message:category:module:lineno
         also PYTHONWARNINGS=arg
-x     : skip first line of source, allowing use of non-Unix forms of #!cmd
-X opt : set implementation-specific option
file   : program read from script file
-      : program read from stdin (default; interactive mode if a tty)
arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
PYTHONPATH   : ';'-separated list of directories prefixed to the
               default module search path.  The result is sys.path.
PYTHONHOME   : alternate <prefix> directory (or <prefix>;<exec_prefix>).
               The default module search path uses <prefix>\lib.
PYTHONCASEOK : ignore case in 'import' statements (Windows).
PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
PYTHONFAULTHANDLER: dump the Python traceback on fatal errors.
PYTHONHASHSEED: if this variable is set to 'random', a random value is used
   to seed the hashes of str, bytes and datetime objects.  It can also be
   set to an integer in the range [0,4294967295] to get hash values with a
   predictable seed.

But if you type...

i.e. python -m pip -h

Then you will get this as your output...

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Usage:
  E:\Program Files\Python\Python37\python.exe -m pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and
                              CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied
                              with --no-index.
  --no-color                  Suppress colored output

So, you can read everything or just skip it. Choice is YOURS. (FOR NEWBIES)

Hope you like the tutorial.

Python is simple and fun to play with and yet very powerful. 🔥



🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Top 40 Python - String Processing in Python | Working with String in Python

Top 11 Essential Python Tips and Tricks

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram