Can't pip install virtualenv in OS X 10.8 with brewed python 2.7

前端 未结 5 763
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 06:00

When trying to install virtualenv using a brewed python, I get the following error:

$ pip install virtualenv
Requirement already satisfied (use --upgrade to          


        
相关标签:
5条回答
  • 2020-12-09 06:42

    I had the same problem and I managed to solve it by uninstalling any brew versions of Python and virtualenv

    brew uninstall python
    brew uninstall pyenv-virtualenv
    

    Manually moving all the virtualenv* files I found under /usr/local/bin to another folder

    sudo mkdir /usr/local/bin/venv-old
    sudo mv /usr/local/bin/virtualenv* /usr/local/bin/venv-old/
    

    Opening a new terminal tab and double-checking that I'm in a clean state

    which python # => /usr/bin/python
    which virtualenv # => virtualenv not found
    

    And installing Python and virtualenv(wrapper) cleanly using the recommended method (here and here):

    brew install python --with-brewed-openssl
    # Open a new terminal tab now (to access /usr/local/bin/python)
    pip install virtualenv
    pip install virtualenvwrapper
    
    0 讨论(0)
  • 2020-12-09 06:43

    I had the same problem and found the solution on a Google group. It seems that /usr/local/bin/virtualenv was not updated so if you open it, you will see a reference to the old virtualenv 1.9.1 when a newer version has been installed on your system.

    So you just need to open /usr/local/bin/virtualenv and replace it with:

    #!/usr/local/bin/python
    # -*- coding: utf-8 -*-
    import re
    import sys
    from virtualenv import main
    
    if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
    

    And that worked for me!

    Source: https://groups.google.com/forum/#!topic/python-virtualenv/hL_QDPJsnuY

    0 讨论(0)
  • 2020-12-09 06:50

    I had the same issue,

    for me

    sudo mv /usr/local/bin/virtualenv* /usr/local/bin/venv-old/

    the

    pip install -I virtualenv

    I didn't have to uninstall and reinstall python.

    0 讨论(0)
  • 2020-12-09 06:51

    I found that unlike you my paths were wrong according to brew doctor. But after correcting that I still had the issue (no surprises given your description) so I uninstalled virtualenv then reinstalled but this time with sudo, sudo pip install virtualenv

    This resolved the issue, which indicates that I've either got another problem with the system configuration in general or someone who has more then my one hour of Python experience will be able to point out why it's not good (I think it's related to global installing being considered a bad practice).

    Seth is onto something with which seems you see the same as me,

    ~ which python results in /usr/local/bin/python

    ~ ls -l /usr/local/bin/python gives me _permissions_etc_ /usr/local/bin/python -> ../Cellar/python/2.7.5/bin/python

    Pip

    which pip pointed to /usr/local/bin/pip

    ls -l /usr/local/bin/pip shows _permissions_etc_ /usr/local/bin/pip -> ../Cellar/python/2.7.5/bin/pip

    Virtualenv (I don't have an output prior to the sudo pip install)

    which virtualenv is /usr/local/bin/virtualenv

    ls -l /usr/local/bin/virtualenv shows _permissions_etc_ /usr/local/bin/virtualenv

    When I created and use a virtualenv I get the following,

    workon ve_test
    which python
    /Users/_username_/.virtualenvs/ve_test/bin/python
    (ve_test)➜  ~PIP_VIRTUALENV_BASE  python --version
    Python 2.7.5
    

    FWIW my .zshrc has the following,

    # Python related
    # http://hackercodex.com/guide/python-virtualenv-on-mac-osx-mountain-lion-10.8/
    # http://docs.python-guide.org/en/latest/dev/virtualenvs.html
    source /usr/local/bin/virtualenvwrapper.sh
    # virtualenv should use Distribute instead of legacy setuptools
    export VIRTUALENV_DISTRIBUTE=true
    # Centralized location for new virtual environments
    export PIP_VIRTUALENV_BASE=$HOME/Projects/PythonVirtualEnv
    # cache pip-installed packages to avoid re-downloading
    export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
    
    0 讨论(0)
  • 2020-12-09 06:57

    What really caused and issue for me was the presence of .pydistutils.cfg in my $HOME directory. That's what forced me to have to use: sudo pip install <package>.

    If you ever have to use sudo to install a package via pip, you're doing it wrong and you need to start troubleshooting your system right away; else everything is going to fail and you won't know why.

    Running: brew doctor will warn you about the .pydistutils.cfg file, so don't forget to monitor the status of that command after making core changes to your system.

    It took me quite a while to track this down, but all is well now. This really helped

    0 讨论(0)
提交回复
热议问题