Install a Python package into a different directory using pip?

后端 未结 16 2422
借酒劲吻你
借酒劲吻你 2020-11-22 05:55

I know the obvious answer is to use virtualenv and virtualenvwrapper, but for various reasons I can\'t/don\'t want to do that.

So how do I modify the command

相关标签:
16条回答
  • 2020-11-22 06:01

    With pip v1.5.6 on Python v2.7.3 (GNU/Linux), option --root allows to specify a global installation prefix, (apparently) irrespective of specific package's options. Try f.i.,

    $ pip install --root=/alternative/prefix/path package_name
    
    0 讨论(0)
  • 2020-11-22 06:03
    pip install packageName -t pathOfDirectory
    

    or

    pip install packageName --target pathOfDirectorty
    
    0 讨论(0)
  • 2020-11-22 06:03

    pip install /path/to/package/

    is now possible.

    The difference with this and using the -e or --editable flag is that -e links to where the package is saved (i.e. your downloads folder), rather than installing it into your python path.

    This means if you delete/move the package to another folder, you won't be able to use it.

    0 讨论(0)
  • 2020-11-22 06:04

    To pip install a library exactly where I wanted it, I navigated to the location I wanted the directory with the terminal then used

    pip install mylibraryName -t . 
    

    the logic of which I took from this page: https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download

    0 讨论(0)
  • 2020-11-22 06:09

    Nobody seems to have mentioned the -t option but that the easiest:

    pip install -t <direct directory> <package>
    
    0 讨论(0)
  • 2020-11-22 06:09

    To add to the already good advice, as I had an issue installing IPython when I didn't have write permissions to /usr/local.

    pip uses distutils to do its install and this thread discusses how that can cause a problem as it relies on the sys.prefix setting.

    My issue happened when the IPython install tried to write to '/usr/local/share/man/man1' with Permission denied. As the install failed it didn't seem to write the IPython files in the bin directory.

    Using "--user" worked and the files were written to ~/.local. Adding ~/.local/bin to the $PATH meant I could use "ipython" from there.

    However I'm trying to install this for a number of users and had been given write permission to the /usr/local/lib/python2.7 directory. I created a "bin" directory under there and set directives for distutils:

    vim ~/.pydistutils.cfg
    
    [install]
    install-data=/usr/local/lib/python2.7
    install-scripts=/usr/local/lib/python2.7/bin
    

    then (-I is used to force the install despite previous failures/.local install):

    pip install -I ipython
    

    Then I added /usr/local/lib/python2.7/bin to $PATH.

    I thought I'd include this in case anyone else has similar issues on a machine they don't have sudo access to.

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