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?
normal install method is :
pip install package
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)) (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.