Running `pip` gives 'command not found' after successful Python homebrew install - python

To preface, I am very bad with the terminal, please be patient with me.
when I run pip I get:
zsh: command not found: pip
I have installed Python 2.7.11 with brew, which should allow pip to work
When I run echo $PATH I get
/usr/local/sbin /Users/Nicolas/.composer/vendor/bin /Library/Frameworks/Python.framework/Versions/3.4/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin
I notice that /usr/local/bin/ is in there, which I understand is where brew executables are linked to
when I run which -a python I get
/usr/local/bin/python
/usr/bin/python
So-- two Python installs. I'm guessing one is the native OSX one and one is the homebrew install.
When I run which python I get
/usr/local/bin/python
So this is the python that gets run when python is called, right?
When I run ls -l $(which python) I get
lrwxr-xr-x 1 Nicolas admin 34 Feb 3 14:26 /usr/local/bin/python -> ../Cellar/python/2.7.11/bin/python
I think this is where the problem is; I notice that there is a /python/2.7.11/libexec folder...
I have also tried brew unlink python && brew link python to no avail
when I try brew list python | grep pip I get a very long list of results
This is probably the most important one
/usr/local/Cellar/python/2.7.11/libexec/pip/pip/__init__.py
I don't know how to proceed from here... I think it has to do with pip being in python/2.7.11/libexec instead of python/2.7.11/bin
I am not familiar with most of this stuff; my understanding of terminal is very limited. I am not sure how to proceed from here. Any and all help is appreciated, thanks.

I ran into this problem myself on OS X. In my case, I finally did a listing of /usr/local/bin, and found that I had links from pip2, pip2.7, pip3, and pip3.6. What I lacked was a link from just pip. I don't know if this is just part of a new standard, or if I was missing something that would select one of the two, or if having both Python 2 and Python 3 installed meant that I didn't get a simple pip command. Either way, running brew doctor didn't reveal or solve any issues.
In this case, just running pip3 or pip2 (instead of pip) seemed to do the trick for me. In my case, I ran pip3 and everything installed and ran as expected.

My Background
I had this same problem, and I think it may have arisen after upgrading to OSX 10.11 (El Capitan). When trying to run pip, I got -bash: pip: command not found I also tried python -m pip which did not work either (no module found). Trying to unlink and relink python through Homebrew did not work.
The Fix
I was able to fix the problem by completely uninstalling and reinstalling python via Homebrew.
brew uninstall python && brew install python
If you want to remove older versions of python too, use
brew uninstall --force python && brew install python
None of my existing pip installs were affected, and are all still listed when I run pip freeze. After the reinstall, the binary is now symlinked to /usr/local/bin/pip, which did not exist before. Strangely, the actual binary in /usr/local/Cellar/python/2.7.11/bin/pip did not exist before the reinstall either.

Uninstalling/reinstalling did not fix it for me but brew provided this info:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /opt/homebrew/opt/python#3.9/libexec/bin
So adding /opt/homebrew/opt/python#3.9/libexec/bin to my path fixed the issue.

Related

How to uninstall python and all packages on mac?

I would like to uninstall all the python version installed and all packages on my MAC.
The python version I get is the following:
python --version
Python 3.7.3
However, I have Python 2.7 folder in Applications.
I also have installed Anaconda and the folder
/Users/myName/anaconda3
I would to uninstall Python 3.7.3 and all the packages I have installed both trough pypi and trough conda
I,once, deleted a python version completely from my mac by doing the following steps on the terminal:
sudo rm -rf “/Applications/Python”
sudo rm -rf /Library/Frameworks/Python.framework
sudo rm -rf /usr/local/bin/python
Then, when the password is prompted, enter it and confirm.
As, for anaconda, I remember deleting it once due to a problem using this software here:
https://nektony.com/mac-app-cleaner/download?productname=Anaconda
It's a download link, so be careful before you click incase you are thinking it contains information about the software etc.
My python version was 3.something, so I am not exactly sure whether it will help with the latest one but I thought my steps might help so I hope it helps :)
I did what Mahir said above, but I had Python 3.9 and the 3.8 that Anaconda had installed. I've uninstalled 3.9, but I couldn't find the folder where the 3.8 was. After some time I've found it inside the Command Line folder in this path here:
cd /Library/Developer/CommandLineTools/usr/bin
Then I deleted all the files/folders related to python with the command below:
sudo rm -rf pip3 pip3.8 pydoc3 pydoc3.8 python3 python3.8
Maybe you'll also have to do this to get rid of python

pip command not found after installed it

I'm stuck with an issue. I have a Python script that I would like to run on my OSX but seems that I crossed on many issues.
To run the script I should have both Python and Moviepy installed.
To install Moviepy I used this command:
sudo pip install moviepy
The response was:
sudo: pip: command not found
So I tried to install pip, with the command:
sudo easy_install pip
And got this answer:
Searching for pip
Best match: pip 9.0.1
Processing pip-9.0.1-py2.7.egg
pip 9.0.1 is already the active version in easy-install.pth
Using /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
I tried to run again the
sudo pip install moviepy
but I still got that issue. What I should do?
UPDATE:
not sure on OSX, but can u try pip3 – Rehan Azher 23 mins ago
sudo pip3 install moviepy
Password:
sudo: pip3: command not found
It seems that pip is not in your path, but as long as Python can find it: sudo python -m pip install moviepy should do it. Check your $PATH env. variable, tho. – zwer 14 mins ago
sudo python -m pip install moviepy
/usr/bin/python: No module named pip
UPDATE2
A good option for you is to consider installing pip using one of OSX's
sources, like the apt program in Debian-based distributions, rather
than easy_install. – Shiva 4 hours ago
sudo apt install moviepy
Password:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/apt" (-1)
No idea why everyone keeps getting stuck on this. You have a
fundamental decision to make when using Python. You either run Python
2.7 that Apple ships and which is ancient and doesn't have pip or you use homebrew and install Python3 and pip3 and put /usr/local/bin at
the start of your PATH. But don't try a mixture of the two. – Mark
Setchell 3 hours ago
Tried to install homebrew but it cannot find the package moviepy that I am looking for.
Try with this:
pip3 install package-name
This works for me!
Yes, it's a mess. Today, your best option is to leave the ageing, OS-provided version of Python (all the stuff in /Library/Python and similar) alone and start fresh.
It looks like you've already done this (since you have an executable at /usr/bin/python) but if not, the easiest way to get Python 2 is to use Homebrew. Install Homebrew using the instructions on the website and then use it to install Python:
brew install python#2
Python 2.7.9+ comes with pip already, but if you've ended up with an older version then use python itself and get-pip.py to install pip (instead of easy_install, which is deprecated):
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
Note that get-pip.py includes a copy of pip in order to install pip effectively. Yes, things are that bad.
Finally, note that Python 2 will be end of life in less than 6 months. If you have the luxury, consider skipping straight to Python 3. Then it's as easy as:
brew install python
because pip3 comes with python3 since version 3.4. Homebrew manages to handle the installation of both Python 2 and Python 3 without conflict.
Note this procedure is different on every operating system and every month or two. But at least it should get you going for the foreseeable future.
Can you go to python shell and type import pip? If that works, then it means the pip package is installed, but there is no command-line script/program available.
In my computer, the command-line pip program is actually a python script in itself, and is located in /usr/local/bin/, which is in my PATH. Below are the contents of my pip script.
#!/usr/bin/python
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
This is a dirty trick. What you could do is to create a new file called pip in your /usr/local/bin/ directory (or similar for OSX) and copy the above lines into it.
sudo touch /usr/local/bin/pip # create a new empty file called "pip"
# ... open the file in your favorite editor, copy the above contents and save the file
sudo chmod +x /usr/local/bin/pip # make it executable
The first line in the file (#!/usr/bin/python), called "Shebang", points to the program that should execute this file when you run it on your command-line. You should put the path to the python program in your computer over there.

Brew install python not pointing to python anymore

I am trying to install jupyter on mac,
I understand that the mac comes with python version installed
But i also installed brew and installed python through brew.
When i check python location i get:
which python
/usr/bin/python
When i check pip location i get:
which pip
/usr/local/bin/pip
When i try to install jupyter:
pip install install
after a long installation it tried to remove python package that it want's to upgrade
And fails:
On trying to uninstall dateutil.
I think its the mac packages.
I tried with sudo, no change.
As far as i can understand it because the files are immutable.
Tried to remove the immutable with:
chflags uchg.
No change.
I also tried to work with virtual env, using:
sudo pip install virtualenvwrapper.
But that pip tries to uninstall another python folder.
Any suggestions?
Thanks
UPDATE:
The brew seems to create links from python2. to python2
And the same for python3.
I tried to create the link myself, It worked and i was manage to install the package i wanted. But its not a good solution,
The all point of brew is to manage this things for me, next time i will upgrade python it will break.
Any suggestions why? could it be because the brew installed two python version on my laptop?
RESOLVED:
Found the answer, thanks to #tdube question i went and looked what brew guys did to python and found this thread from Jan 17.
I turns out that they changed the behavior or installing python.
No you don't have simply python any more.
You have python2 and python3.
No more simply pip, now you have pip2 and pip3.
That is a major change from the default behavior of how people use python
Especially that mac comes with a default python
so now you have
python that is /usr/bin/python
python2 that is /usr/local/bin/python2
python3 that is /usr/local/bin/python3
this is the fix, the brew guys suggest ( you can see it when running brew info python ):
==> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.zshrc:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
Pip and setuptools have been installed. To update them
pip2 install --upgrade pip setuptools
You can install Python packages with
pip2 install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: http://docs.brew.sh/Homebrew-and-Python.html
You can read about it in this thread:
The Python that comes "pre-installed" on Mac is located in /usr/bin/python. I think you need to change the order of the entries in your PATH environment variable as noted here (python homebrew by default). Which file your PATH is set in depends on which shell you are using.

Pip suddenly using wrong version of Python

Having a weird problem with pip on os x.
As far as I can recall (and a quick look at my .bash_history seems to confirm) I have not made any recent changes to my configuration. Alas, the pip command seems to be suddenly using a different version of python than it was previously. Up until now I was using the command pip to manage my python2 libraries and pip3 to manage by python3 libraries. Suddenly, any attempts at running pip install fails with errors like missing parenthesis around print statements.
Here is the result of a few commands I attempted to figure out the problem:
which pip > /usr/local/bin/pip
which pip3 > /usr/local/bin/pip3
which python > /usr/local/bin/python
python version > Python 2.7.11
pip --version > pip 8.1.1 from /usr/local/lib/python3.5/site-packages (python 3.5)
So for some reason the pip command seems to be running from the PyPi2 database but in python3 now? Any ideas how to fix this?
I run with multiple Python versions and thus multiple pip versions as well.
Everytime, however, you update pip, you'll replace the standard pip command with the version you updated. So even pip3 install --upgrade pip will put a /usr/local/bin/pip in your system, messing up the Python 2 version.
Instead, I run pip as an (executable) module:
python3 -m pip search <package>
or
python2 -m pip search <package>
or even
python3.5 -m pip search <package>
This guarantees that your pip version always matches the Python version you want to use it for. It's somewhat longer to type, but I prefer the expliciteness of it (which, I guess, follows the Zen of Python).
Note that updating pip:
python3.5 -m pip install --upgrade pip
will still install a Python 3.5 version in /usr/local/bin/pip, but I'm simply ignoring that. Just beware of (shell) scripts that execute pip directly.
Find absolute path to Python you'd like to use:
which python
Open your default pip executable script:
vi $(which pip)
You will see a shebang line at the top which may point to wrong Python (i had that once too).
Point to the Python you want (see step 1), e.g.:
#!/usr/local/bin/python3.7
Try setting aliases by running the following commands in Terminal,
alias pip="/usr/local/bin/pip"
alias pip2="/usr/local/bin/pip"
alias pip3="/usr/local/bin/pip3"
If this solves your problem then you need to add the aliases in your bash profile.
Look How do I create a Bash alias? for more info.
Alternatively, you have to reinstall pip using python2 get-pip.py first and then python3 get-pip.py get-pip.py can be downloaded here https://bootstrap.pypa.io/get-pip.py
I had exactly the same problem!
I reinstall python2 by brew brew reinstall python#2
after reinstall, pip install packagename works!
None of these worked for me so what I did was navigate to
C:\Users(User)\AppData\Local\Programs\Python\
and deleted all the old python versions I wasn't using. (Worked)

How to fix broken python 2.7.11 after OSx updates? An in-depth look into Homebrew and beyond

What happened:
After an OSx update and installing a new version of python 2.7 my virtualevn environment completely broke and I struggled in fixing it. I wasn't sure what caused it and went through a whole set of things that I did and read initially that didn't work are listed below. What solved my problem is provided in the answer section.
What didn't work to fix virtualenv command not found:
Installed python through homebrew and then used pip to install virtualenv
Installed python through https://www.python.org and then used pip to install virtualenv
Related questions that helped me but did not provide the solution to my problem:
virtualenv-command-not-found
virtualenv-workon-command-not-found
Complete manual recovery I went through (What not to do!):
This didn't completely solved my problem. It is just to give you an idea of what steps I went through before I found the correct way to fix my python dev environment on my OSx.
Removed python 2.7 by using the post in here
Removed the homebrew installed version
Installed python through the pkg file in Mac OS X 32-bit i386/PPC installer or Mac OS X 64-bit/32-bit installer
Manually installed virtualenv following the instructions from here:
curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-13.1.2.tar.gz
tar xvfz virtualenv-13.1.2.tar.gz
cd virtualenv-13.1.2
sudo python setup.py install
Manaully install pip through 7:
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
PIP was still broken after all this:
After all this after creating a virtual environment my pip still installed the packages in the main python folder instead of installing them under the virtual environment and non of the threads here neither here helped. My solution to that was to run pip under my virtual env with the following options:
1- Activate the virtual environment so that $VIRTUAL_ENV is set:
source venv/bin/activate
2- Forces pip to install in the right destination:
pip install --target=$VIRTUAL_ENV/lib/python2.7/site-packages
Summary
Something was badly broken and best way I fix my dev environment is provided in the answer to this question.
The reason
In my case was an OSx upgrade that affected my homebrew and after upgrading to python 2.7.11 is didn't install it properly.
How I got it to work:
I found steps 3 and 4 in a thread here and many thanks to https://github.com/baronomasia.
1 - Removed python 2.7 by using the post in here
2 - Removed the homebrew python installed version
brew uninstall python
3- Reinstall your Xcode command tools:
sudo xcode-select --install
4- Upgrade homebrew and reinstall python through homebrew:
brew update && brew reinstall python
After doing brew upgrade python my system python was broken and was throwing fits about virtualenvwrapper.sh, as well as my pip command was just suddenly missing.
I went to python.org and downloaded the python 2.7.13 installer, ran it, I now have python 2.7.13, pip, and can run pip install virtualenvwrapper and things seem to work.

Categories

Resources