distutils在构建扩展时会忽略对setup.py的更改吗? [英] distutils ignores changes to setup.py when building an extension?

查看:97
本文介绍了distutils在构建扩展时会忽略对setup.py的更改吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个setup.py文件来构建扩展名.如果我更改了一个源文件,则distutils会识别出该文件并重建扩展名,并显示所有的compile/link命令.

I have a setup.py file that builds an extension. If I change one of the source files, distutils recognizes this and rebuilds the extension, showing all the compile / link commands.

但是,如果我唯一更改的是setup.py(我想使库依赖项起作用),那么它似乎没有重建(例如,没有显示任何compile/link命令).我已经通过删除该行中的一个源文件进行了测试

However, if the only thing I change is setup.py (I'm fiddling trying to make library dependencies work), then it doesn't seem to rebuild (e.g., none of the compile/link commands show up). I've tested this by removing one of the source files in the line

sources = ['foo.c', 'bar.c' ...]

,当我pip install -e .python setup.py install时,它仍会为扩展名创建一个新文件,但它必须是某个地方缓存的版本,因为它不应该编译.

and when I pip install -e . or python setup.py install, it still creates a new file for the extension, but it must be a version cached somewhere, since it shouldn't compile.

如何清除此缓存?我尝试过

How do I clear this cache? I have tried

python setup.py clean --all

或在执行pip install -e .

我发现进行重建的唯一方法是,如果我在源文件中添加垃圾,触发重建和错误,删除垃圾,然后再次pip install -e . ...

The only way I have found to make it rebuild is if I add garbage in a source file, triggering a rebuild and error, remove the garbage, and pip install -e . again...

推荐答案

  1. 只需删除site-packages路径下的任何与其相关的文件,有时您可能会发现一个以上版本或打包为zip文件的某些文件,或者运行以下命令python setup.py clean --all.
  2. 重新编译并重新安装.
  1. Just delete under site-packages path any file related to it, you may find sometimes more than one version or some files packaged as zip files or run the following command python setup.py clean --all.
  2. Recompile and install again.

但是我建议使用python setup.py develop,因此您无需每次更改都重新安装它,您将能够经常编辑代码,而不必再次重新安装. python setup.py install通常用于安装可立即使用的第三方程序包.

But I will recommend to use python setup.py develop so you don't need to reinstall it with every change, you will be able to frequently edit your code and not have to re-install it again. python setup.py install is used to install typically a ready to use third-party packages.

选中此处可更好地了解 Python包装

Check here to better understand python packaging.

摘要:

python setup.py clean --all
python setup.py develop

这篇关于distutils在构建扩展时会忽略对setup.py的更改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆