`pip install --upgrade pip` vs. `python -m pip install --upgrade pip` - python

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

How uninstall pip3

I am having some problems with pip when trying to install a python application.
It says its not able to find pip3, but its installed
Digging deeper I think I have locations where pip3 is installed.
While trying to uninstall, even that is not working since it referring to the other pip3
How to I go about keeping only one copy of pip3 and uninstall one copy of it
$which pip3
/home/frappeuser/.local/bin/pip3
$ sudo pip3 uninstall pip
sudo: unable to execute /usr/local/bin/pip3: No such file or directory
You can unninstall it using python in cmd using the following:
python3 -m pip uninstall pip
In case you are using python 2.0
python -m pip uninstall pip
python - refers to the python version that you are working with
-m - refers to the option module
pip - specifies the module name that you want to use
uninstall - the operation you want to do
pip - the module that you want to uninstall
/local/ means you have it installed not via package manager, so to uninstall it you have to provide the full path:
sudo /home/frappeuser/.local/bin/pip3 uninstall pip

Python : py and pip commands [duplicate]

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).

What's the difference between calling pip as a command line command, and calling it as a module of the python command?

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.

pip is rolling back

I have a problem with the pip python 3.x installation.
I have pip version 19.0.3, but when i use pycharm, it keeps saying that i need the pip updated.
when i check the folder, I can see there is another version of pip pip-10.0.1-py3.7.egg in the folder.
I remember ticking the option to add the python in the environment path when i installed python.
When I tried to update/install pip again, i got the error.
(venv) C:\Users\ranic\PycharmProjects\ProjectDatabase>pip help install
You are using pip version 10.0.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(venv) C:\Users\r\PycharmProjects\ProjectDatabase>python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\users\r\pycharmprojects\projectdatabase\venv\lib\site-packages (19.0.3)
Thank you in advance.
If you check, I guarantee that pip is not in the same place as python.
Mine are, seen below:
C:\Users\adsmith>where pip
C:\Users\adsmith\AppData\Local\Programs\Python\Python36-32\Scripts\pip.exe
C:\Users\adsmith>where python
C:\Users\adsmith\AppData\Local\Programs\Python\Python36-32\python.exe
but I'm guessing your python is referring to Python2, and pip Python3 (or vice versa). If you find the version of Python that pip refers to, you should be able to do:
path/to/that/python -m pip install --upgrade pip

pip won't install Python packages locally with --user

I'm trying to install packages locally with pip. It used to work with --user but now when I try it, it finds the version of the package in /usr/local/lib/ and then does not install it locally. Normally it would install things in ~/.local but now it just checks the system-wide dir for the package and if it's there, it does not install it (which is not what I want) and if it's not there, it tries to install it in /usr/local/lib which I do not have write permissions at. Eg:
$ pip install --user rpy2
Requirement already satisfied (use --upgrade to upgrade): rpy2 in /usr/local/lib/python2.7/dist-packages/
How can I make pip install --user always go to ~/.local and not a system-wide directory?
Citing Marcus Smith (maintainer of pip):
If you think the global site is out of date, and want the latest in
the user site, then use:
pip install --upgrade --user SomePackage
If the global site is up to date, and you really just want the same
thing duplicated in --user, then use:
pip install --ignore-installed --user SomePackage (which works correctly now after the merge of #1352, which is to be released in v1.5)
How can I make pip install --user always go to ~/.local and not a system-wide directory?
Use both --upgrade and --ignore-installed arguments.
According to the pip documentation, that syntax is correct, but requires Python 2.6.
User Installs
With Python 2.6 came the “user scheme” for installation, which means
that all Python distributions support an alternative install location
that is specific to a user. The default location for each OS is
explained in the python documentation for the site.USER_BASE variable.
This mode of installation can be turned on by specifying the –user
option to pip install.
Moreover, the “user scheme” can be customized by setting the
PYTHONUSERBASE environment variable, which updates the value of
site.USER_BASE.
To install “SomePackage” into an environment with site.USER_BASE
customized to ‘/myappenv’, do the following:
export PYTHONUSERBASE=/myappenv
pip install --user SomePackage
So the following entry should work for you:
export PYTHONUSERBASE=~/.local
pip install --user rpy2
installing any package using user command
for upgrading pip :
python -m pip install --upgrade --user pip

Categories