以编程方式获得python在前缀中安装路径,而无需撤销

发布于 2025-01-28 02:26:58 字数 659 浏览 3 评论 0 原文

由于 distutils 正在从&gt中的python中删除; 3.10版本和setuptools不会添加到stdlib,我想替换现有的 setup.py 用于构建/安装C ++库Cython Extension的配方(即不主要是Python软件包,不在VENV等)带有一些自定义代码。

Cython部分工作正常,我几乎设法通过使用 sysconfig 使用config-var info 构建了对C ++编译器的同等调用。 ...尽管后者是反复试验的,但据我所知,与配置var集合没有任何文档或特殊的一致性。

但是,我现在坚持确定哪个目录将我的build Extension .so 安装到我的构建的目标前缀中。取决于使用中的平台和路径方案以及前缀本身,这些子段可以在 lib lib64 中, pythonx.y subdir某种形式的 dist-packages 或其他目录。此决定以前是由 distutils 做出的,但是我找不到任何等效的代码来返回其他stdlib软件包中的此类决策。

有答案或最佳实践方法的建议吗? (请使用“使用setuptools”,请!)

As distutils is being removed from Python in the > 3.10 versions, and setuptools will not be added to the stdlib, I want to replace an existing setup.py recipe for building/installing a C++ library Cython extension (i.e. not primarily a Python package, not run in a venv, etc.) with some custom code.

The Cython part is working fine, and I just about managed to construct an equivalent call to the C++ compiler from that previously executed by distutils, by using config-var info from sysconfig... though the latter was very trial and error, with no documentation or particular consistency to the config-var collection as far as I could tell.

But I am now stuck on identifying what directory to install my build extension .so into, within the target prefix of my build. Depending on the platform and path scheme in use, and the prefix itself, the subdirs could be in lib or lib64, a pythonX.Y subdir of some sort, and a final site-packages, dist-packages or other directory. This decision was previously made by distutils but I can't find any equivalent code to return such path decisions in other stdlib packages.

Any suggestions of answers or best-practice approaches? (Other than "use setuptools", please!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2025-02-04 02:26:58

这对我有用:

from sysconfig import get_path
get_path('platlib', 'posix_user', {'userbase': '/prefix/path/'})

我在 $ {cmake_install_dir} 的路径中使用了它。

This worked for me:

from sysconfig import get_path
get_path('platlib', 'posix_user', {'userbase': '/prefix/path/'})

I used it in a CMakeLists.txt with ${CMAKE_INSTALL_DIR} for the path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文