Install a Python package into a different directory using pip?

后端 未结 16 2651
借酒劲吻你
借酒劲吻你 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: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.

提交回复
热议问题