pip list and sudo pip list shows different package versions - python

I have a Mac, I installed Python with Homebrew and I installed packages with pip. But I found out when I call pip list and sudo pip list, it actually gives different package versions. For example, I have ipython (3.1.0) in sudo pip list and ipython (2.3.0) in just pip list. What does it mean? Do I have two both versions installed?
The reason I found out about it is because when I upgrade some of the packages, my system denied the permission, so I used sudo, did I do it wrong?

The answer is pretty easy: your python environment is using different paths. do
$ which pip
$ sudo which pip
and you'll get two different paths.
Seriously consider changing over to use python virtualenv, which gets you lots better control.

Related

I'm confused about the difference between pip and pip3, in anaconda env

TL;DR: a package is installed under pip3, but it cannot be found under Python3. Why?
All of this is happening in my anaconda base environemnt:
So I've been struggling with tensorflow and its versions (another post coming up).Turns out version 2.1 is only available at pip and not with conda install. So after upgrading pip3 install --upgrade pip I install pip3 install tensorflow==2.1.0. I open Jupyer-Notebook afterwards, and turns out tensorflow is not installed(running Python3). I check from the terminal first for the version, and then to uninstall tensorflow. It is not installed under pip (as expected) but it is indeed installed under pip3. I also get this message when uninstalling via pip3:
"pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly."
which might be related. I was under the impression that pip installs packages for the default python (3.7.4 in my case) but pip3 installs them only for Python3. What am I missing?
Thanks!
a package is installed under pip3, but it cannot be found under Python3. Why?
Because you have many different Pythons. pip doesn't install packages for all Pythons; pip3 doesn't install packages for Python3. They install packages for that particular Pythons they're running under. You cannot expect to install a package with one Python and import it in another eve if they're of the same version.
To see what Python is used with a particular pip see its shebang:
head -1 $(which pip)
head -1 $(which pip3)
If the shebang is #!/usr/bin/env python continue investigating with which python (or which python3).
Finding the Python run python -m site to see where from the packages are imported.

pip list and sudo pip list show different package versions

I am using Ubuntu 16.04, python2.7 and pip 9.0.1
When I call pip list and sudo pip list, I get different answers.
In contrast to this similar question, which pip and sudo which pip give the same answer: /usr/local/bin/pip
Note also, that pip uninstall <packagename> sometimes gives me No files found to uninstall, but then sudo pip uninstall does find and uninstall the packages. Packages thus uninstalled remain on the list of pip list, but not on sudo pip list. I do not know if all discrepancies between the two lists happened like this.
I think pip list is showing all the packages installed by current user
and sudo pip list is showing all the packages installed by super user
you won't be able to uninstall the package install by super user.
There are system packages in /usr/[local/]lib/{site,dist}-packages/, local (for a user) packages in ~/.local/lib and packages in a virtualenv. sudo pip skips virtualenvs and runs as a different user (root), hence the difference.

Downgrading python package installed locally

In the server that work in (as do many other people) the "global" python has a certain version of a package, say 1.0.0.
I recently used pip to upgrade that to 1.0.2 locally for my user with the pip install --user package==1.0.2, which worked. However, now I want to uninstall my locally installed version and remain with the global one.
I've tried pip uninstall --user package==1.0.2, pip uninstall --user package, and a few other options but nothing seems to work. I always get this error:
Usage:
pip <command> [options]
no such option: --user
I also tried pip install --user package=1.0.0 but now I have both versions installed locally and python uses the most recent.
How can I do what I want?
Apparently this cannot be done with pip directly. I ended up solving it just by removing the package from ~/.local/lib/python3.5/site-packages/. A bit more manual than I was hoping I'd have to do.
The --user option for pip seems to have been removed but is still an option with setuptools.
So if you want to use the --user function what you can do is use pip download which will download the .whl file. You then need to extract the file using wheel unpack. I then ran python setup.py install --user (worked for numpy) and it installed the package to my home directory under .local.
I followed the documentation here.

Should I manually install all my system wide packages after upgrading to Python 3?

I have some systemwide packages I've installed and I'm unclear whether I'm supposed to install another copy of them all for Python3 or if there is some way to 'point' Python3 at them. I'm on a Mac.
I still have Python 2.7.9 which has all the packages (most installed with either brew or pip and maybe one or two manually like pyqt). Do I basically have to redo the installation process for every single package again? Or is there some way to simply have Python3 'inherit' everything I've installed so far under 2.7.9?
Also, from what I understand, to install under Python3 with pip I would use pip3 install, is that correct? How would I do the same with ones installed with Homebrew? Is there a brew3 command? Or does Homebrew install to all versions of Python?
You do need to reinstall, but I would step away from systemwide installs in general and start using project-specific package installation.
Use pyenv for version switching and virtualenv for isolated environments.
pyvenv works rather well.
Install Python 3
python -m venv "my_virtual_env"
my_virtual_env\Scripts\activate
pip search lib
pip install ...
You will have to look up what the activate command is for osx. pip is the standard package manager now. You can search, install, and uninstall with pip. Pip is also moving towards wheels when installing packages. You probably don't have to worry about wheels too much though.

Unable to upgrade python six package in mac osx 10.10.2

I am trying to install latest version of six python package but I have following issues. Can't get rid of six 1.4.1 in mac OSX 10.10.2
sudo pip install six --upgrade
Requirement already up-to-date: six in /Library/Python/2.7/site-packages
Cleaning up...
pip search six
six - Python 2 and 3 compatibility utilities
INSTALLED: 1.9.0 (latest)
python -c "import six; print six.version"
1.4.1
which -a python
/usr/bin/python
which -a pip
/usr/local/bin/pip
What is wrong here? Can't upgrade six!
I resolved the problem by the following method.
Download the six-1.10.0.tar.gz package
Use this command to install it.
python setup.py install
This works because it installs the new version of six to /Library/Python/2.7/site-packages/ which is searched before /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/
Your pip binary belongs to /usr/local/bin/python, whereas python points to /usr/bin/python. As a consequence
pip install --upgrade six
will install to /usr/local/bin/python.
The command below will make sure that the right version of pip is used:
python -m pip install --upgrade six
For me, just using homebrew fixed everything.
brew install python
What worked for me was to use easy_install instead of pip.
easy_install -U six
Easy_install managed to upgrade the package even when pip failed.
Mac OS X's default python is installed as a framework.
Under the framework directory, there is an 'Extras' directory and six package is already placed there.
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py
According to the description (https://github.com/MacPython/wiki/wiki/Which-Python), /System/Library/Frameworks/Python.framework/Versions/2.7/Extras is listed before /Library/Python/2.7/site-packages in module search path.
This means all packages already exists in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras can't upgrade.
Maybe you should install python manually and not to use default python.
I came across this exact issue when using pip to install the openstack client. My fix was to use easy_install instead of pip, as it utilizes /Library/Python/2.7/site-packages/ for module installation instead of the /System/Library/Frameworks/Python.framework/Versions/2.7/Extras. If this workaround is not an option for you, then I can confirm that #Masakazu Matsushita has the correct workaround of setting PYTHONPATH to /Library/Python/2.7/site-packages. To implement that workaround, add this line:
export PYTHON_PATH=/Library/Python/2.7/site-packages
to your ~/.bashrc and ~/.profile (if its a GUI Python application that you are trying to install).
Try these steps
Reinstall python using brew
$ brew install python
Resolve missing symlink problem
$ brew link --overwrite python
Reboot system or run
$ hash -r python
Try with pip2 its work for me
pip2 install -U six
While one or another of the above solutions may work for you, I think it's important to understand what is going on and what are the options that you have. I found this (rather lengthy) description to be very useful: it starts with outlining the options and only then suggests solutions.
In the end, the problem for me was that I was using the IPython shell.
which ipython returned /usr/local/bin/ipython and upon inspection this file declared at the top #!/usr/bin/python, which seemed to be circumventing all my best efforts to use the correct python location.
Simply changing this line #!/usr/local/bin/python to point to the correct python version then meant IPython used the correct six module.

Categories