What is the difference between:
pip install --upgrade pip
and
python -m pip install --upgrade pip
and why is python -m pip install --upgrade pip generally favoured?
The difference is between pip and python -m pip; the rest of the command doesn't matter. The reason to prefer the latter is that you're ensuring that the python you normally use is the one which will provide the pip module you invoke. Otherwise, there is a risk that the pip executable found in your PATH is from an unrelated or out of date Python installation; it might install packages, but your regular python invocation won't find them (because they're installed for a non-default Python).
You can also modify the second command to invoke specific Python executable names (python2.7 vs. python3.8), or even absolute paths if you might have versions with the same name installed in multiple places.
The first one
pip install --upgrade pip
is to invoke pip as a command. The actual python interpretor called is not explicit. The second one is calling the python interpretor explicitly, so you know which one is called.
There should be no difference, as the __main__.py in the module and the pip script are both point to the same entry point, unless in the case that the default python is different from the one used by the pip script
If i am correct, pip install --upgrade pip and python -m pip install --upgrade pip are the same unless you specify the pip or python version.
The latter is preferred because it attempts to upgrade the pip associated with the specified python version (e.g. python3.7 -m pip install --upgrade pip) even if the main python version is different (python command may refer to any python version).
Related
What is the difference between:
pip install --upgrade pip
and
python -m pip install --upgrade pip
and why is python -m pip install --upgrade pip generally favoured?
The difference is between pip and python -m pip; the rest of the command doesn't matter. The reason to prefer the latter is that you're ensuring that the python you normally use is the one which will provide the pip module you invoke. Otherwise, there is a risk that the pip executable found in your PATH is from an unrelated or out of date Python installation; it might install packages, but your regular python invocation won't find them (because they're installed for a non-default Python).
You can also modify the second command to invoke specific Python executable names (python2.7 vs. python3.8), or even absolute paths if you might have versions with the same name installed in multiple places.
The first one
pip install --upgrade pip
is to invoke pip as a command. The actual python interpretor called is not explicit. The second one is calling the python interpretor explicitly, so you know which one is called.
There should be no difference, as the __main__.py in the module and the pip script are both point to the same entry point, unless in the case that the default python is different from the one used by the pip script
If i am correct, pip install --upgrade pip and python -m pip install --upgrade pip are the same unless you specify the pip or python version.
The latter is preferred because it attempts to upgrade the pip associated with the specified python version (e.g. python3.7 -m pip install --upgrade pip) even if the main python version is different (python command may refer to any python version).
When installing python modules, I seem to have two possible command line commands to do so.
pip install {module}
and
py -{version} -m pip install {module}
I suppose this can be helpful for selecting which version of python has installed which modules? But there's rarely a case where I wouldn't want a module installed for all possible versions.
Also the former method seems to have a pesky habit of being out-of-date no matter how many times I call:
pip install pip --upgrade
So are these separate? Does the former just call the latest version of the latter?
TLDR: Prefer ... -m pip to always install modules for a specific Python version/environment.
The pip command executes the equivalent of ... -m pip. However, bare pip does not allow to select which Python version/environment to install to – the first match in your executable search path is selected. This may be the most recent Python installation, a virtual environment, or any other Python installation.
Use the ... -m pip variant in order to select the Python version/environment for which to install a module.
So the pip install module is callable if you have already installed the pip. The pip install pip --upgrade upgrades the pip and if you replace the pip into a module name it will upgrade that module to the most recent one. the py -{version} -m pip install {module} is callable if you have installed many versions of python - for example most of the Linux servers got installed python 2, so when you install the Python 3, and you want to install a module to version 3, you will have to call that command.
I want to uninstall one package named fp_growth
so I use this operation in command:
python -m pip uninstall fp_growth
I also use:
python -m pip uninstall fp_growth pip3
but it shows same errors here.
how to solve it?
ERROR: Cannot uninstall 'fp-growth'. It is a distutils installed
project and thus we cannot accurately determine which files belong to
it which would lead to only a partial uninstall.
Try using this
python -m pip uninstall fp_growth
If you are using Python3 then replace pip by pip3
Have you tried python -m pip uninstall fp_growth to uninstall using pip?
The pip command, when used with python -m (or python3 -m) doesn't require a version modifier like it does when used standalone as pip uninstall fp_growth or pip3 uninstall fp_growth.
Go to C:\Users\ (Current User Name)\AppData\Local\Programs.
Delete Python Folder.
Go to Control Panel >> Uninstall a Program.
Right Click on Python and then Change/Modify.
Click on Repair Python. Note: This will Fail but be Patient.
Now Again go to step 3.
Now, after step 3, uninstall Python.
I'm trying to write a script that uses speedtest-cli, I have installed the module with pip install speedtest-cli. If I run pip install speedtest-cli I get the following
Requirement already satisfied: speedtest-cli in /usr/local/lib/python2.7/site-packages
If I try to use pip with the default python, as recommended by another answer here, like so python -m pip install speedtest-cli I get
/usr/bin/python: No module named pip
I figured that the pip is setup for one of the other versions of python but the only version of python in /usr/local/bin is python3 and in /usr/bin there is python, python2.6, and python2.7 but I have tried defining each ones of those as the interpreter at the top of the file and none of them works, each producing giving the same import error on the speedtest module.
Which version of python is pip linked to then, or why is the installed module not importing?
The easiest solution was to completed a fresh start.
Remove all references to easy_install, python, and pip using the following;
rm -r easy_install*
rm -r pip*
rm -r python*
Then I used this guide to properly install, setup, and configure python with HomeBrew, with pip and virtualenv installed.
The article is fairly lengthy so I'm not going to copy it all out here but here is an image snapshot in case the link goes dead.
I have a macbook pro, and I have Python 2.7,3.3 and 3.4 and Anaconda 2.7 installed, and I am having a hard time managing all these multiple Python distributions. These are the problems I am facing :
pip install installs for anaconda 2.7 by default, how do I make it install for PYthon 2.7 ?
how do I make pip3 install work for different Python distributions? i.e is there some way I can use something like pip3 install -v 3.3.6 or something similar.
how do I find a workaround for these problems. I wish to know the answer in both the basic sense (how Python and Anaconda work, and what happens when I use pip install, and how do I use these to solve my problem), and also in the practical sense (is there some simple way to manage this problem).
To install packages for specific python versions, it is easiest to run python with the -m flag. The -m flag will run the specified module as a script. Calling python -m pip install _package_ will run pip for whatever python you specify.
Examples:
python -m pip install _package_
python3 -m pip install _package_
python2.7 -m pip install _package_
python3.7 -m pip install _package_