Install a Python package into a different directory using pip?

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

    Installing a Python package often only includes some pure Python files. If the package includes data, scripts and or executables, these are installed in different directories from the pure Python files.

    Assuming your package has no data/scripts/executables, and that you want your Python files to go into /python/packages/package_name (and not some subdirectory a few levels below /python/packages as when using --prefix), you can use the one time command:

    pip install --install-option="--install-purelib=/python/packages" package_name
    

    If you want all (or most) of your packages to go there, you can edit your ~/.pip/pip.conf to include:

    [install]
    install-option=--install-purelib=/python/packages
    

    That way you can't forget about having to specify it again and again.

    Any excecutables/data/scripts included in the package will still go to their default places unless you specify addition install options (--prefix/--install-data/--install-scripts, etc., for details look at the custom installation options).

提交回复
热议问题