Can't install Pip Packages in El Capitan (10.11) - python

Okay, so I have brew, and I've brew reinstalled python since El Capitan.
MacBook-Pro-2:decipher Alex$ which python
/usr/local/bin/python
MacBook-Pro-2:decipher Alex$ whereis python
/usr/bin/python
I have two pythons. That's all well and good. Brew doctor is clean, except for some Unbrewed header files were found in /usr/local/include, none of which seem related to Python. Short of virtualenv, is there any way to install packages anymore? I feel like I might be missing something.
Just like this guy I was trying to get IPython. I don't really need it, so I gave up the other day. Now I need Pylint. If I try to install it with pip:
IOError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/logilab_common-1.1.0-py2.7-nspkg.pth'
Does anyone know how to point pip towards another instance of python on my system, or do something else so I can have the old behavior back? Please?
-- EDITS --
Suggested was the idea of using /usr/local/bin/pip to install ipython. This is the output. I can't figure out how to use ipython still.
MacBook-Pro-2:MNIST Alex$ /usr/local/bin/pip install ipython[all]
Requirement already satisfied (use --upgrade to upgrade): ipython[all] in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): traitlets in /usr/local/bin (from ipython[all])
Requirement already satisfied (use --upgrade to upgrade): pickleshare in /usr/local/bin (from ipython[all])
Requirement already satisfied (use --upgrade to upgrade): simplegeneric>0.8 in /usr/local/bin (from ipython[all])
... the rest of the requirements are all satisfied in usr/local/bin

I had trouble too with El Capitan. I did these things and it worked:
1) Install Homebrew
2) Install Python 3 with Homebrew
3) In terminal enter these installs (in this order)
$ pip3 install pyobjc-core
$ pip3 install pyobjc
$ pip3 install pillow
$ pip3 install pyautogui

To point pip to another Python instance of your system, you need to use pip from the same bin/ folder where python is installed so it resolves to the same site-packages.
Example:
/usr/local/bin/pip install logilab_common
To make /usr/local/ writable by a local user on OSX do:
sudo chown -R `whoami`:admin /usr/local/*
More information
http://blog.blakesimpson.co.uk/read/89-fix-homebrew-error-usr-local-bin-is-not-writable-on-os-x-el-capitan

As Mikko Ohtamaa points out in the comments, somehow, I had a version of python in a folder called /lib. I'm not sure how it got there. I think that's the version of python I was using. Once I just sudo rm -rf /lib everything suddenly worked.

Related

pip list returns -bash: pip: command not found

I am checking the documentation and there are basically two ways to install pip.
python -m ensurepip --upgrade
Looking in links: /var/folders/d0/gnksqzwn2fn46fjgrkp6045c0000gn/T/tmpe2ll6upv
Requirement already satisfied: setuptools in /Applications/Anaconda/anaconda3/lib/python3.9/site-packages (58.0.4)
Requirement already satisfied: pip in /Applications/Anaconda/anaconda3/lib/python3.9/site-packages
All the packages are in /Applications/Anaconda/anaconda3/lib/python3.9/site-packages directory including pip.
However, when I run pip list from base environment, I get:
-bash: pip: command not found
I am getting module not found error when running my application.
My application was running fine until I tried to upgrade a python package. What did I mess up? What do I need to check?
Try this python -m pip list instead of python pip list
It could be that pip might not be installed or it could be the version of the pip might not be compatible with the current version.
pip used for python2, use pip3 for python3 and upgrade your pip and retry once.
python -m pip install --upgrade pip

`pip` doesn't upgrade itself

I can't upgrade pip (9.0.1) to pip (10.0.1).
Running
pip install --upgrade pip
throws
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/EGG-INFO/PKG-INFO'
(this is yet another issue I will need to deal with...)
Trying
pip install --user pip
returns
Requirement already satisfied: pip in /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
and has no effect, i.e. pip list | grep pip returns pip (9.0.1)
Running
pip install --upgrade --user pip
returns
Successfully installed pip-10.0.1
but pip list | grep pip still returns pip (9.0.1)
I have learned not to use sudo, so please don't suggest this.
This answer suggests to install by hand (more or less). But I am worried of messing things up.
If you are suggesting to use a virtual environment, I am afraid this is one level of sophistication too many for me as I am still very much a beginner, and if something doesn't work the way it should I will find it even more daunting to figure out what to try.
Is there really no alternative than the latter options?
You can "safely" delete everyting in /Library/Python/2.7/site-packages/, except for:
$ cat Extras.pth
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
You can do it from the Finder (it should ask for your Admin credentials) or in a pinch with sudo rm - carful!
I'd recommend removing everything there - which should get rid of any packages you previously installed with pip or easy_install - and only ever using pip install --user from then on or better yet use pyenv from homebrew to get Python 3 and use virtual environments from then on.

Python packages hash not matching whilst installing using pip

I am using pip to install all my python packages but get error as shown in the trace below. What is the problem and how can I solve it?
usr#comp:~$ pip install flask
Collecting flask
Using cached Flask-0.11.1-py2.py3-none-any.whl
Collecting itsdangerous>=0.21 (from flask)
Using cached itsdangerous-0.24.tar.gz
Collecting click>=2.0 (from flask)
Using cached click-6.6.tar.gz
Collecting Werkzeug>=0.7 (from flask)
Using cached Werkzeug-0.11.11-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /usr/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): MarkupSafe in /usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)
THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
Werkzeug>=0.7 from https://pypi.python.org/packages/a9/5e/41f791a3f380ec50f2c4c3ef1399d9ffce6b4fe9a7f305222f014cf4fe83/Werkzeug-0.11.11-py2.py3-none-any.whl#md5=c63a21eedce9504d223ed89358c4bdc9 (from flask):
Expected md5 c63a21eedce9504d223ed89358c4bdc9
Got 13a168aafcc43354b6c79ef44bb0dc71
There is a similar problem (Why does pip fail with bad md5 hash for package?) from 2013 the solution that I tried that worked for me is this:
sudo pip install --no-cache-dir flask
given by attolee
The problem here is the Python package was updated with new hash value while pip was trying to install the Python package using the old hash value cached in pip cache directory. This cache needs to be purge before the pip install attempt. So the full solution is:
python -m pip cache purge
python -m pip install <package>
--no-cache-dir did not work for me in raspberry pi 4 at first.
Found that the problem was due to unexpected network change/failure during pip installation
I had to download the broken .whl file manually with wget
and install it like below:
sudo pip install scipy-1.3.0-cp37-cp37m-linux_armv7l.whl
followed by
sudo pip install --no-cache-dir keras
Then it worked.
Looks like a cache problem, the cached package is different from REQUIREMENTS.
Perhaps caused by last updates interruption.
I did this which fixed my problem:
rm ~/.cache/pip -rf
You need to upgrade your pip into the newer version:
Using this command:
python -m pip install -upgrade pip
for Mac/Linux operating system and use
python -m pip install --upgrade tensorflow
for Windows to update your pip. Then run your command
pip install flask
In case you got this error while using pipenv try
$ pipenv --clear
$ pipenv lock
$ pipenv install
first, try to upgrade your pip then install the library
python -m pip install -upgrade pip
if it didn't work just try to install it without the cash
pip install --no-cache-dir the_library_name
I got the error during installing panads
You need to remove the cache and reinstall .
pip install --no-cache-dir flask
I had a similar issue for a different module. It was caused by network failure. My fix was nothing complex but another attempt at installing it and it worked.
maybe pipiserver(where you pip install from) upload a pkg for example flask-1.0.0.tar.gz, and rm is upload a new flask-1.0.0.tag.gz,if new pkg code has changed ,the hash must be different,there is two ways:
installl an older pkg version =, pip install flask==0.0.9
wait new pkg release flask==1.0.1 or cache expiration.
I have tried to clear pip cache with "-m pip cache purge" and using the "--no-cache-dir" argument but it was not helping.
In my case it was VPN being active during the attempts to install the package. As soon as I have turned it off everything worked as expected.

Python packages not installing in virtualenv using pip

I'm having trouble installing twisted
pip --version
pip 1.1 from
/home/chris/GL/GLBackend/glenv/lib/python2.7/site-packages/pip-1.1-py2.7.egg
(python 2.7)
Create a virtual environment
chris#chris-mint ~/GL/GLBackend $ sudo virtualenv -p python2.7 glenv
Running virtualenv with interpreter /usr/bin/python2.7 New python
executable in glenv/bin/python2.7 Also creating executable in
glenv/bin/python Installing
distribute.............................................................................................................................................................................................done.
Installing pip...............done.
Just in case, I'll enable all permissions
chris#chris-mint ~/GL/GLBackend $ sudo chmod -R 777 glenv
chris#chris-mint ~/GL/GLBackend $ source glenv/bin/activate
(glenv)chris#chris-mint ~/GL/GLBackend $ pip freeze
argparse==1.2.1 distribute==0.6.24 wsgiref==0.1.2
twisted is not listed here as installed
(glenv)chris#chris-mint ~/GL/GLBackend $ sudo pip install twisted
Requirement already satisfied (use --upgrade to upgrade): twisted in
/usr/local/lib/python2.7/dist-packages Requirement already satisfied
(use --upgrade to upgrade): zope.interface>=3.6.0 in
/usr/local/lib/python2.7/dist-packages (from twisted) Requirement
already satisfied (use --upgrade to upgrade): distribute in
/usr/local/lib/python2.7/dist-packages (from
zope.interface>=3.6.0->twisted) Cleaning up... (glenv)chris#chris-mint
~/GL/GLBackend $ pip uninstall twisted Cannot uninstall requirement
twisted, not installed Storing complete log in
/home/chris/.pip/pip.log
But when I install it it says that its already installed.
Force the install:
sudo pip install -I twisted
Downloading/unpacking twisted Downloading Twisted-12.3.0.tar.bz2
(2.6Mb): 2.6Mb downloaded Running setup.py egg_info for package
twisted
. . .
Successfully installed twisted zope.interface distribute Cleaning
up...
And yet it still isn't installed
(glenv)chris#chris-mint ~/GL/GLBackend $ pip freeze
argparse==1.2.1 distribute==0.6.24 wsgiref==0.1.2
**When I try running Python scripts which use twisted, I get an error saying that twisted is not installed. That is:
ImportError: No module named twisted.python**
The problem here is that you're using sudo when you shouldn't be. And that's causing pip to try to install into /usr/local/lib instead of ~/glenv/lib. (And, because you used sudo, it's successfully doing so, but that doesn't help you, because you're not allowing system site-packages in your venv.)
There are multiple reasons sudo pip could lead to this behavior, but the most likely is this: On most systems (including the various Mac and RHEL/CentOS boxes I have immediate access to), the sudoers file will reset your environment, then add back in a handful of whitelisted environment variables. This means that when you sudo pip, it will not see the environment variables that virtualenv sets up, so it will fall back to doing the default thing and install into your system Python, instead of your venv.
But really, it doesn't matter why this is happening. The answer is the same: just do pip install instead of sudo pip install.
Note that you also want to remove the sudo on the virtualenv call, as this will probably cause the venv to be set up incorrectly (which is why you need the sudo chmod, which wouldn't be necessary otherwise). The whole point of installing things under your user home directory is that you can do it with your normal user permissions.
As a side note, you also may want to upgrade to a newer virtualenv/pip, as 1.8 and 1.2 have some bug fixes and improvements. But I verified that I get exactly the same problem as you even with the latest (1.8.4 and 1.2.1) versions, so I don't think that's relevant here.
The sudo pip is causing the problem here. It will install the package in your system instead of the virtual environment you created. So when it says the requirement is already satisfied. Try to look add the directory it is pointing to. Which is in your case, while you were trying to install, was /usr/local/lib/python2.7/dist-packages
If it's inside something like /usr/local/lib/..., which does not points to your virtualenv folder then it is installed in your system. Otherwise, in correct scenario it will look something like this /usr/local/lib/..../<name of your virtualenv>/lib.
You can always use commands like which python & which pip to see if they both are using the placeholder of our virtual environment.

How to install virtualenv scripts to /usr/bin

I install virtualenv with command sudo /usr/bin/pip-2.6 install virtualenv
And it says
Requirement already satisfied (use --upgrade to upgrade):
virtualenv in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Why pip from /usr/bin looks to /usr/local/lib?
I need to install virtualenv scripts directly to /usr/bin, so I write
sudo /usr/bin/pip-2.6 install --install-option="--install-scripts=/usr/bin" virtualenv
But again it responds with
Requirement already satisfied (use --upgrade to upgrade):
virtualenv in /usr/local/lib/python2.6/dist-packages
Cleaning up...
Adding --upgrade doesn't help.
How can I install virtualenv scripts to /usr/bin ?
For your current issue can you first uninstall virtualenv using pip, and then reinstall using --script-dir=DIR, -s DIR as an --install-option.
As for your issue running pip with extra arguments and install not seeming to do anything, that may be fixed on develop branch at https://github.com/pypa/pip if not please file a bug with us on the GitHub issue tracker for pip.
As to why it is behaving like this - the install is based on the python installation not on the location of pip. Pip uses setuptools/distribute under the hood and conforms to the configuration of the python it is running under.
You can see where the version of python you are using installs to by running it - in this case probably python2.6 and querying the sys module.
>>> import sys
>>> sys.prefix
>>> sys.exec_prefix
See also distutils.sysconfig
For more information:
Installing Python Modules
setuptools
distribute
Try:
sudo /usr/bin/pip-2.6 install --install-option="--prefix=/usr/bin" virtualenv
(source).

Categories