setup.py 安装默认使用另一个 site-packages 目录

Use another site-packages directory by default for setup.py install

我在应用程序中嵌入了 Python。当用户通过

安装包或模块时
{...}\myapp\python\python.exe setup.py install

软件包将安装在

{...}\myapp\python\lib\site-packages

是否有机会使用另一个目录代替默认

要添加新的站点包目录,请将该新目录路径添加到路径配置文件中。

路径配置文件将允许您添加一个额外的站点包目录。如果您不想要现有的站点包目录,您可以将其从 PYTHON_PATH.

中删除

echo "new_site-package_directory" > your_site_packages_path/usrlocal.pth

要做到这一点,您需要注意的事项很少。我做了一些研究,这是我发现的:

这部分摘自Python's docs:

After the build command runs (whether you run it explicitly, or the install command does it for you), the work of the install command is relatively simple: all it has to do is copy everything under build/lib (or build/lib.plat) to your chosen installation directory.

If you don’t choose an installation directory—i.e., if you just run setup.py install—then the install command installs to the standard location for third-party Python modules. This location varies by platform and by how you built/installed Python itself.

大多数 Linux 发行版包括 Python 作为系统的标准部分,因此前缀和 exec-prefix 通常都是 Linux 上的 /usr。如果您在 Linux(或任何类 Unix 系统)上自己构建 Python,则默认前缀和执行前缀为 /usr/local.

prefixexec-prefix 代表 Python 安装到的目录,以及它在 运行 时找到其库的目录。

你有办法交替安装位置,直到某个点:你可以交替base目录,但不能交替安装方案

The Distutils install command is designed to make installing module distributions to an alternate location simple and painless. The basic idea is that you supply a base directory for the installation, and the install command picks a set of directories (called an installation scheme) under this base directory in which to install files. The details differ across platforms, so read whichever of the following sections applies to you.

“home scheme”背后的想法是构建和维护 Python 模块的个人存储。该方案的名称源自 Unix 上“主”目录的概念,因为 Unix 用户将其主目录设置为类似于 /usr/ 或 /usr/local/ 的布局并不罕见。任何人都可以使用此方案,无论他们安装的操作系统是什么。

python setup.py install --home=<dir>

--home 选项定义安装基目录。文件安装到安装库下的以下目录如下:

modules home/lib/python
scripts home/bin
data    home
C headers   home/include/python/distname

然后您需要修改 Python's search path 以找到新位置。

您还可以使用定义安装基础的 --prefix 选项 python setup.py install --prefix=。阅读更多相关信息 here


总而言之,您可以更改 home 目录,但站点包层次结构将在其中构建。