After upgrading pip
(or pip3
, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package>
and pip3 install --user <package>
(for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python
for python3
, and pip
for pip3
)
Had same problem on macOS as well, it's a common issue across platforms.
To completely remove and reinstall pip and pip3 in all currently supported versions of Ubuntu open the terminal and type:
sudo apt purge python-pip python3-pip
sudo apt install python-pip python3-pip
pip uninstall --user pip
pip3 uninstall --user pip3
Removing a package removes all packaged data, but leaves usually small (modified) user configuration files behind, in case the remove was an accident. Just issuing an installation request for the accidentally removed package will restore its function as before in that case. On the other hand you can get rid of these leftovers by calling purge
even on already removed packages. Note that this does not affect any data or configuration stored in your home directory.
Best Answer
sudo
sanitizes the environment before running any command. In doing so, if the value of the directivesecure_path
is set, it will be used as thePATH
for thesudo
commands, not the currentPATH
.In my system:
So i have:
What you can do to keep your current path or add
/usr/.../anaconda3/bin
tosudo
'sPATH
:Pass
PATH
in the environment of thewhich
command:Any desired
PATH
can be set too.Keep the current environment while running
sudo
by:Disable the
secure_path
value by putting a#
in front or remove the line to keep the currentPATH
:Instead, you can also modify the
secure_path
to just add/usr/.../anaconda3/bin
to it, at the beginning.Add
PATH
to theenv_keep
directive to keep thePATH
in thesudo
provided environment: