Python Forum
A couple of questions about pip install
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A couple of questions about pip install
#1
I am new to Python. At first I understood that packages are to be installed via the command prompt with
 py -m pip install [package_name]
. However, I have just installed a package that excluded the "py -m" part. Why isn't the py -m part necessary, and why is it included if not necessary?

Also, why do packages have to be installed via command prompt? Is there a parallel way to install them directly via the Python interpreter itself?
Reply
#2
normal install method is :
pip install package
Reply
#3
First the the basic part about Path,in newer version of Windows installer for Python like 3.5-->.
There is a option under install to Add Python 3.6 to Path as i show in this tutorial.
So if start cmd:
Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. Med enerett.

C:\Windows\System32>cd\

C:\>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

C:\>pip -V
pip 9.0.1 from c:\python36\lib\site-packages (python 3.6)
C:\>
The pip install some_package will work from anywhere in cmd and always install to 3.6.
Running .py files from anywhere in cmd with python my_scripts.py will always use 3.6


About py Launcher.
Python 3.3--> introduces Python Launcher for Windows that is installed into c:\Windows\ as py.exe.
This launcher can load any Python version install on your OS.
I usually have 5-6 Python version installed and a main one the newest(3.6) set in Path as show over.
Demo of py launcher:
C:\1
λ py -2.7 version.py
Hello from 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)]

C:\1
λ py -3.4 version.py
Hello from 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)]

C:\1
λ py -3.5 version.py
Hello from 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]

λ py -3.6 version.py
Hello from 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)]

C:\1
# using py launcher to install into 2.7 
λ py -2.7 -m pip install requests
Collecting requests
  Using cached requests-2.18.4-py2.py3-none-any.whl
  .....
  Successfully installed certifi-2017.7.27.1 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
The version.py file i am running to show what version is used is this one.
I always use cmder if you wonder about λ,a tutorial.
import sys

print('Hello from {}'.format(sys.version))
Reply
#4
(Oct-12-2017, 01:40 AM)Athenaeum Wrote: I am new to Python. At first I understood that packages are to be installed via the command prompt with
 py -m pip install [package_name]
. However, I have just installed a package that excluded the "py -m" part. Why isn't the py -m part necessary, and why is it included if not necessary?

Also, why do packages have to be installed via command prompt? Is there a parallel way to install them directly via the Python interpreter itself?

pip is a python module that happens to be callable by itself.  py -m {module} or python -m {module} will call python, and run the module named, with whatever arguments you give it.  In this case, that'd run pip with the arguments install {package}.  But because pip is also a standalone program, you can skip that first part, and just do pip install {package}.

tldr: they're two different ways of doing the same thing.  As far as I know, the only time you actually need to use python -m pip {etc}, is if you're having pip update itself.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A couple of questions Led_Zeppelin 1 892 Sep-30-2022, 07:05 PM
Last Post: deanhystad
  More than a couple problems. MurphysLaw 7 3,190 Apr-12-2021, 09:11 PM
Last Post: virginiaturner
  Need help understanding a couple of functions (encrypt,decrypt, int_to_bytes) xoani 0 1,968 Jun-09-2019, 03:25 PM
Last Post: xoani
  Couple of questions about modules Winfried 6 3,828 Aug-24-2018, 08:38 PM
Last Post: Winfried
  just a couple questions.... medievil 5 3,560 May-05-2018, 03:13 AM
Last Post: medievil
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 34,475 Nov-25-2017, 06:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020