问题:Python setup.py开发与安装

在setup.py两个选项develop,并install混淆了我。根据此站点,使用develop创建到site-packages目录的特殊链接。

人们建议我使用python setup.py install全新安装,并且python setup.py develop对安装文件进行任何更改之后。

谁能阐明这些命令的用法?

Two options in setup.py develop and install are confusing me. According to this site, using develop creates a special link to site-packages directory.

People have suggested that I use python setup.py install for a fresh installation and python setup.py develop after any changes have been made to the setup file.

Can anyone shed some light on the usage of these commands?


回答 0

python setup.py install 用于安装(通常是第三方)您不会自行开发/修改/调试的软件包。

对于您自己的东西,您想要首先安装您的软件包,然后能够频繁编辑代码不必每次都重新安装该软件包-正是python setup.py develop这样:安装软件包(通常只是一个源文件夹)以某种方式可以让您在将代码安装到(虚拟)环境后方便地编辑代码,并使更改立即生效。

请注意,强烈建议使用pip install .(安装)和pip install -e .(开发人员安装)来安装软件包,因为setup.py直接调用将对许多依赖项(例如pull prereleases和不兼容的软件包版本)做错事,或者使软件包难以使用卸载pip

python setup.py install is used to install (typically third party) packages that you’re not going to develop/modify/debug yourself.

For your own stuff, you want to first install your package and then be able to frequently edit the code without having to re-install the package every time — and that is exactly what python setup.py develop does: it installs the package (typically just a source folder) in a way that allows you to conveniently edit your code after it’s installed to the (virtual) environment, and have the changes take effect immediately.

Note that it is highly recommended to use pip install . (install) and pip install -e . (developer install) to install packages, as invoking setup.py directly will do the wrong things for many dependencies, such as pull prereleases and incompatible package versions, or make the package hard to uninstall with pip.


回答 1

文档中。该develop不会安装软件包,但它会创建一个.egg-link部署目录回项目源代码目录。

因此,这就像安装,而不是复制到其中,site-packages而是添加了一个符号链接(.egg-link充当多平台符号链接)。

这样,您可以编辑源代码并直接查看更改,无需在每次进行少量更改时都重新安装。如果您是该项目的开发者,因此很有用,名称为develop。如果您只是在安装别人的软件包,则应使用install

From the documentation. The develop will not install the package but it will create a .egg-link in the deployment directory back to the project source code directory.

So it’s like installing but instead of copying to the site-packages it adds a symbolic link (the .egg-link acts as a multiplatform symbolic link).

That way you can edit the source code and see the changes directly without having to reinstall every time that you make a little change. This is useful when you are the developer of that project hence the name develop. If you are just installing someone else’s package you should use install


回答 2

人们在使用该develop方法时可能会发现有用的另一件事是可以--user选择不使用sudo进行安装。例如:

python setup.py develop --user

代替

sudo python setup.py develop

Another thing that people may find useful when using the develop method is the --user option to install without sudo. Ex:

python setup.py develop --user

instead of

sudo python setup.py develop

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。