I don't know what's the deal but I am stuck following some stackoverflow solutions which gets nowhere. Can you please help me on this?
Monas-MacBook-Pro:CS764 mona$ sudo python get-pip.py
The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/mona/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
/tmp/tmpbSjX8k/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
Collecting pip
Downloading pip-7.1.0-py2.py3-none-any.whl (1.1MB)
100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 1.1MB 181kB/s
Installing collected packages: pip
Found existing installation: pip 1.4.1
Uninstalling pip-1.4.1:
Successfully uninstalled pip-1.4.1
Successfully installed pip-7.1.0
Monas-MacBook-Pro:CS764 mona$ pip --version
-bash: /usr/local/bin/pip: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
This question is related to
python
macos
installation
pip
osx-mavericks
Editing the first line of this file worked to me:
MBP-de-Jose:~ josejunior$ which python3
/usr/local/Cellar/python/3.7.3/bin/python3
MBP-de-Jose:~ josejunior$
before
#!/usr/local/opt/python/bin/python3.7
after
#!/usr/local/Cellar/python/3.7.3/bin/python3
In my case, I decided to remove the homebrew python installation from my mac as I already had two other versions of python installed on my mac through MacPorts. This caused the error message.
Reinstalling python through brew solved my issue.
I had the same issue. I have both Python 2.7 & 3.6 installed. Python 2.7 had virtualenv
working, but after installing Python3, virtualenv kept looking for version 2.7 and couldn't find it.
Doing pip install virtualenv
installed the Python3 version of virtualenv.
Then, for each command, if I want to use Python2, I would use virtualenv --python=python2.7 somecommand
I had similar issue. Basically pip was looking in a wrong path (old installation path) or python. The following solution worked for me:
which python
)/usr/local/bin/pip2.7
and /usr/local/bin/pip
). The line should state the correct path to the python path. In my case, didn't. I corrected it and now it works fine.In case it helps anyone, the solution mentioned in this other question worked for me when pip stopped working today after upgrading it: Pip broken after upgrading
It seems that it's an issue when a previously cached location changes, so you can refresh the cache with this command:
hash -r
For me, on centOS 7 I had to remove the old pip link from /bin by
rm /bin/pip2.7
rm /bin/pip
then relink it with
sudo ln -s /usr/local/bin/pip2.7 /bin/pip2.7
Then if
/usr/local/bin/pip2.7
Works, this should work
sudo /usr/bin/easy_install pip
this command worked out for me
I'm guessing you have two python installs, or two pip installs, one of which has been partially removed.
Why do you use sudo
? Ideally you should be able to install and run everything from your user account instead of using root. If you mix root and your local account together you are more likely to run into permissions issues (e.g. see the warning it gives about "parent directory is not owned by the current user").
What do you get if you run this?
$ head -n1 /usr/local/bin/pip
This will show you which python binary pip
is trying to use. If it's pointing /usr/local/opt/python/bin/python2.7
, then try running this:
$ ls -al /usr/local/opt/python/bin/python2.7
If this says "No such file or directory", then pip is trying to use a python binary that has been removed.
Next, try this:
$ which python
$ which python2.7
To see the path of the python binary that's actually working.
Since it looks like pip was successfully installed somewhere, it could be that /usr/local/bin/pip
is part of an older installation of pip that's higher up on the PATH
. To test that, you may try moving the non-functioning pip
binary out of the way like this (might require sudo
):
$ mv /usr/local/bin/pip /usr/local/bin/pip.old
Then try running your pip --version
command again. Hopefully it picks up the correct version and runs successfully.
To simplify to operation, we can use the below command to reinstall version 2:
brew install python@2
Then on my mac, it looks as below:
? python -V
Python 2.7.10
? python2 -V
Python 2.7.14
? python3 -V
Python 3.6.5
? pip2 -V
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)
? pip3 -V
pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)
? pip --version
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)
All you need to do is... close the terminal window and reopen new one to fix this issue.
The issue is, new python path is not added to bashrc(Either source or new terminal window would help).
Because I had both python 2 and 3 installed on Mac OSX I was having all sorts of errors.
I used which to find the location of my python2.7 file (/usr/local/bin/python2.7)
which python2.7
Then I symlinked my real python2.7 install location with the one the script expected:
ln -s /usr/local/bin/python2.7 /usr/local/opt/python/bin/python2.7
Only solution in OSX and its variant.
ln -s /usr/local/bin/python /usr/local/opt/python/bin/python2.7
For this error:
~/Library/Python/2.7/bin/pip: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory`
The source of this problem is a bad python path hardcoded in pip (which means it won't be fixed by e.g. changing your $PATH). That path is no longer hardcoded in the lastest version of pip, so a solution which should work is:
pip install --upgrade pip
But of course, this command uses pip, so it fails with the same error.
The way to bootstrap yourself out of this mess:
which pip
#!/usr/local/opt/python/bin/python2.7
to e.g. #!/usr/local/opt/python2/bin/python2.7
(note the python2 in the path), or any path to a working python interpreter on your machine.pip install --upgrade pip
(this overwrites your hack and gets pip working at the latest version, where the interpreter issue should be fixed)For me, I found this issue by first having the identical issue from virtualenv:
~/Library/Python/2.7/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory`
The solution here is to run
pip uninstall virtualenv
pip install virtualenv
If running that command gives the same error from pip, see above.
I got same problem. If I run brew link --overwrite python2
. There was still zsh: /usr/local/bin//fab: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory
.
cd /usr/local/opt/
mv python2 python
Solved it! Now we can use python2 version fabric.
=== 2018/07/25 updated
There is convinient way to use python2 version fab when your os python linked to python3. .sh
for your command.
# fab python2
cd /usr/local/opt
rm python
ln -s python2 python
# use the fab cli
...
# link to python3
cd /usr/local/opt
rm python
ln -s python3 python
Hope this helps.
You could have two different versions of Python and pip.
Try to:
pip2 install --upgrade pip
and then pip2 install -r requirements.txt
Or pip3
if you are on newer Python version.
TLDR: pip
found in your path a is a symlink and the referenced location no longer contains the executable. You need to update the symlink.
It helps to understand a couple of things.
python
or pip
you os will search /etc/paths
to try to find the associated executable for that command. You can see everything in there by using cat /etc/paths
.which
, you can type which python
or which pip
. This will tell you the location of the executable that your shell will use for that command./etc/paths
to contain /usr/local/bin
, its also common for /usr/local/bin
to be a bunch of symlinks to the actual executables. Not the executables themselves.bad interpreter: No such file or directory
With that being said the problem is likely that pip
is a symlink and the linked executable probably doesn't exist at that location anymore. To fix it do the following
which pip
(gives something like this /usr/local/bin/pip
)ls -l /usr/local/bin/pip | grep pip
(give something like this pip -> /usr/local/opt/[email protected]/bin/pip3
)ls /usr/local/opt/[email protected]/bin/pip3
(you are having this issue so it probably doesn't).rm -r /usr/local/bin/pip
pip
executable if using homebrew
it will be in /usr/local/opt
you can use something like ls /usr/local/opt/ | grep python
to find it.ln -s /usr/local/opt/[email protected]/bin/pip3 /usr/local/bin/pip
I had the same issue, virtualenv was pointing to an old python path. Fixing the path resolved the issue:
$ virtualenv -p python2.7 env
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
$ which python2.7
/opt/local/bin/python2.7
# needed to change to correct python path
$ head /usr/local/bin/virtualenv
#!/usr/local/opt/python/bin/python2.7 <<<< REMOVED THIS LINE
#!/opt/local/bin/python2.7 <<<<< REPLACED WITH CORRECT PATH
# now it works:
$ virtualenv -p python2.7 env
Running virtualenv with interpreter /opt/local/bin/python2.7
New python executable in env/bin/python
Installing setuptools, pip...done.
I made the same error using sudo for my installation. (oops)
brew install python
brew linkapps python
brew link --overwrite python
This brought everything back to normal.
Source: Stackoverflow.com