Installing pip on macOS Sierra

前端 未结 7 1048
执念已碎
执念已碎 2021-01-31 20:11

I\'ve been trying to install pip on macOS sierra via brew, but every time it completes without installing the binaries in /usr/local/Cellar/python/2.7.13/bin.

相关标签:
7条回答
  • 2021-01-31 20:36

    I had this issue and I found this to be the solution. BTW pip isn't installed via brew. It comes with python and python virtualenvs.

    if you type which python without brew install python you'll get the location in /usr/bin/python. That is the system python which we don't want to develop with.

    So i took the following steps. 1) brew install python 2) export PATH="/usr/local/opt/python/libexec/bin:$PATH" place that in your ~/.bash_profile 3) source ~/.bash_profile in your terminal 4) type which python and that should have changed the location to /usr/local/opt/python/libexec/bin/python.

    This will allow you to pip install normally and use the brew version of python.

    Now before high sierra python used to be located in /usr/local/bin but for some reason if you place /usr/local/bin in your paths it automatically points back to /usr/bin, so this is the only solution I have been able to come up with.

    Python3 does not have this issue, if you brew install python3 and type which python3 you'll see that it's located in /usr/local/bin/python3.

    0 讨论(0)
  • 2021-01-31 20:36

    For what it's worth, after upgrading to high sierra I found my machine pretty much unusable for development, even crashing plenty of times.

    Regarding python, i had a rights issue inside the site-packages folder, therefore the reinstall did not work out:

    $ brew reinstall python
    
    ==> Reinstalling python
    ==> Downloading https://homebrew.bintray.com/bottles/python-2.7.14.high_sierra.bottle.tar.gz
    Already downloaded: /Users/m/Library/Caches/Homebrew/python-2.7.14.high_sierra.bottle.tar.gz
    ==> Pouring python-2.7.14.high_sierra.bottle.tar.gz
    ==> /usr/local/Cellar/python/2.7.14/bin/python2 -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7.14/bin --install-
    Last 15 lines from /Users/m/Library/Logs/Homebrew/python/post_install.01.python2:
    .
    .
    .
    copying build/lib/setuptools/script (dev).tmpl -> /usr/local/lib/python2.7/site-packages/setuptools
    copying build/lib/pkg_resources/_vendor/packaging/version.py -> /usr/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging
    error: could not delete '/usr/local/lib/python2.7/site-packages/pkg_resources/_vendor/packaging/version.py': Permission denied
    Warning: The post-install step did not complete successfully
    ...
    

    So to fix it, I completely removed the site-packages:

    $ sudo rm -rf /usr/local/lib/python2.7/site-packages
    

    With this, reinstalling python2, and having a working pip2 again, worked like a charm:

    $ brew reinstall python
    
    $ which pip2
    /usr/local/bin/pip2
    $ which python2
    /usr/local/bin/python2
    
    $ which pip
    pip not found
    $ which python
    /usr/bin/python
    

    Hope that helps.

    0 讨论(0)
  • 2021-01-31 20:41

    For Mac OS Sierra, cannot install pip via easy_install since there is a problem with TLS Version, Installed Open-SSL version won't support TLS 1.2

    So install pip using curl as follows,

    curl https://bootstrap.pypa.io/get-pip.py | sudo python
    
    0 讨论(0)
  • 2021-01-31 20:45

    Something must be wrong with your brew installation.

    Latest macOS version.

     ~/ brew reinstall python
    ==> Reinstalling python
    ==> Downloading https://homebrew.bintray.com/bottles/python-2.7.13.sierra.bottle.tar.gz
    Already downloaded: ~/Library/Caches/Homebrew/python-2.7.13.sierra.bottle.tar.gz
    ==> Pouring python-2.7.13.sierra.bottle.tar.gz
    ==> Using the sandbox
    ==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7
    ==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7
    ==> /usr/local/Cellar/python/2.7.13/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python/2.7
    ==> Caveats
    Pip and setuptools have been installed. To update them
      pip install --upgrade pip setuptools
    
    You can install Python packages with
      pip install <package>
    
    They will install into the site-package directory
      /usr/local/lib/python2.7/site-packages
    
    See: https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md
    
    .app bundles were installed.
    Run `brew linkapps python` to symlink these to /Applications.
    ==> Summary
                                                                        
    0 讨论(0)
  • 2021-01-31 20:46

    You just need to install pip which is not automatically installed in macOS Sierra.

    Run sudo easy_install pip

    0 讨论(0)
  • 2021-01-31 20:46

    OK gang, lots of these answers where helpful but none of them got me to the finish line. I am running High Sierra 10.13.4. The problem as documented above is that Brew installs pip in the /usr/local/bin directory but Python is in /usr/bin (although as Carl said, Python3 correctly goes to /usr/local/bin).

    My immediate use case is related to getting the Postgres BigSQL package to install.

    The steps I took are as follows:

    1. Clear out the brew cache $ rm -rf ~/Library/Caches/Homebrew
    2. Clear out the site-packages $ sudo rm -rf /usr/local/lib/python2.7/site-packages
    3. Reinstall Python $ brew reinstall python This pulls down python-3.5.6.high_sierra and put it in /usr/local/bin/python3
    4. But which python still shows /usr/bin/python
    5. The solution is to run brew install python@2 which pulls down python@2-2.7.14_3.high_sierra
    6. Now which python shows the correct path /usr/local/bin/python which is also where all your pip stuff is installed, so now pip will work.
    7. Of course if you have not installed the latest version of pip you should do that too with sudo pip install --upgrade pip
    0 讨论(0)
提交回复
热议问题