Pip Install not installing into correct directory?

前端 未结 10 1066
小蘑菇
小蘑菇 2020-11-29 04:22

I can\'t seem to use sudo pip install correctly so that it installs into the following directory:

/Library/Frameworks/Python.framework/Versions/2.7/lib/pyth         


        
相关标签:
10条回答
  • 2020-11-29 04:48

    Virtualenv is your friend

    Even if you want to add a package to your primary install, it's still best to do it in a virtual environment first, to ensure compatibility with your other packages. However, if you get familiar with virtualenv, you'll probably find there's really no reason to install anything in your base install.

    0 讨论(0)
  • 2020-11-29 04:49

    1 - Something that might work

    The pip executable is actually a Python script.

    By default it contains (on Linux):

    #!/usr/bin/python
    # EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.5.6','console_scripts','pip'
    __requires__ = 'pip==1.5.6'
    import sys
    from pkg_resources import load_entry_point
    
    if __name__ == '__main__':
        sys.exit(
            load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
        )
    

    So if you got the same in MacOS, pip would always use /usr/bin/python.

    But this is a default. You can still provide the version of python you want either by editing the file or by using python explicitly.

    If which python returns /usr/bin/python then something went wrong when you installed your own version. If it is /Library/Frameworks/Python.framework/Versions/2.7/bin/python, you can directly call:

    sudo python `which pip` install scikit-learn --upgrade
    

    However, chances are high that it won't work. The reason is that sudo is resetting all your environment variables. To make it work, the easiest would be to use:

    sudo -E pip install scikit-learn --upgrade
    

    or

    sudo -E python `which pip` install scikit-learn --upgrade
    

    depending on your setup.

    2 - What you should do

    pip was not thought of as something that root should execute. The actual best way to use it is to install a local, non-root, python version. You just have to make sure that you use it by default by setting up the correct environment variables (such as PATH on Linux) and then install pip without sudo using that python version.

    An even better way would be to setup virtualenvs from your root install.

    This way, you can install/update whatever you want without root privileges and never bother again about why sudo pip is not working. You would also avoid to provide root privileges to whatever is on Pypi and that would warrant that you don't mix system libs with your own.

    0 讨论(0)
  • 2020-11-29 04:50
    1. download pip at https://pypi.python.org/pypi/pip (tar)
    2. unzip tar file
    3. cd to the file’s directory
    4. sudo python2.7 setup.py install
    0 讨论(0)
  • 2020-11-29 04:50

    You Should uninstall the existed python,then download new version.

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