简体   繁体   English

distutils在构建扩展时忽略对setup.py的更改?

[英]distutils ignores changes to setup.py when building an extension?

I have a setup.py file that builds an extension. 我有一个构建扩展的setup.py文件。 If I change one of the source files, distutils recognizes this and rebuilds the extension, showing all the compile / link commands. 如果我更改了其中一个源文件,distutils会识别这个并重建扩展,显示所有编译/链接命令。

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 (eg, none of the compile/link commands show up). 但是,如果我唯一改变的是setup.py(我正在努力使库依赖工作),那么它似乎没有重建(例如,没有编译/链接命令显示)。 I've tested this by removing one of the source files in the line 我已经通过删除该行中的一个源文件来测试它

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

and when I pip install -e . 当我点击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. 或者python setup.py install ,它仍然为扩展创建一个新文件,但它必须是某个地方缓存的版本,因为它不应该编译。

How do I clear this cache? 如何清除此缓存? I have tried 我试过了

python setup.py clean --all

or using the --ignore-installed and --no-cache-dir flags when doing pip install -e . 或者在执行pip install -e .时使用--ignore-installed--no-cache-dir标志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 . 我发现重建它的唯一方法是,如果我在源文件中添加垃圾,触发重建和错误,删除垃圾,以及pip install -e . again... 再次...

  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 . 只需在site-packages路径下删除任何与之相关的文件,您可能会发现有时会将多个版本或某些文件打包为zip文件或运行以下命令python setup.py clean --all
  2. Recompile and install again. 重新编译并重新安装。

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 develop这样你就不需要在每次更改时重新安装它,你就可以经常编辑你的代码,而不必再重新安装它。 python setup.py install is used to install typically a ready to use third-party packages. python setup.py install通常用于安装即用型第三方软件包。

Check here to better understand python packaging . 点击这里以更好地了解python包装

Summary : 摘要

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

I needed to run 我需要跑

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

Thanks to DhiaTN for getting me there. 感谢DhiaTN让我到那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM