在没有 C++ 编译器的情况下安装 python 包

Installing python package without a C++ compiler

我正在尝试在没有 C++ 编译器的 Windows 7 机器上将 HDBSCAN 包安装到 运行。不幸的是,安装编译器不是一个选项。 我读到一些软件包有预编译的 wheel 文件,不需要安装编译器。 installation notes 状态 "Binary wheels for a number of platforms are available thanks to the work of Ryan Helinski"。但是,没有提到在哪里可以找到这些。那么我的问题是:

  1. 如何获取 HDBSCAN 包的 .whl 文件?
  2. 是否可以简单地在另一台机器上编译安装并复制?如果是这样,我编译的机器与代码必须 运行 的机器有什么共同点?我可以在 Windows 10 机器上做吗,还是必须是 Win7,做同样的 Windows 更新需要在两者上都 运行,等等?

这是您可以下载 wheel 文件的站点:https://www.lfd.uci.edu/~gohlke/pythonlibs/ 对于 python 3.5> 或旧版本的 PyPi

  • 运行 python -m pip install thefiledownloadedforyourpythonversion.whl

对于第二个问题,是的,你可以,但是相当复杂,你应该尽可能避免:)

看起来没有项目维护者自己在 PyPI.

上发布的预构建 wheel 发行版

正如其他贡献者已经提到的,可以从第三方获得这样的 wheel 发行版,例如 Christoph Gohlke's "Unofficial Windows Binaries for Python Extension Packages".

当然也可以在一台机器上自己构建这样的 wheels,然后在另一台机器上重复使用。据我所知,在 Windows 的情况下,两台机器都需要具有相同的 Python 解释器(次要)版本以及相同的 bitness(两者32 位或均为 64 位)。操作系统的确切版本无关紧要(从 Windows 10 到 Windows 7 或其他方式应该有效)。

我最终通过在另一台机器上编译并从中复制包来让它工作。所需包在两台机器上的版本相同这一点至关重要,因此我只是设置了一个新的 conda 环境,该环境与目标机器具有相同的包版本,然后在那里安装了带有 pip 的 hdbscan,并进行了复制。 我担心 Windows 版本兼容性,但即使我安装在 Windows 10 上并移动到 运行 Win7.

机器上,这仍然有效

我刚查过。 Python 3.8 is coded in C. You need a C compiler, not a C++ one. MINGW is one, and TinyCC Win32 is another one (a small one, producing quickly slow executables). Look also into this list 个免费的 C 或 C++ 编译器。

一种可能性(可能需要几天的工作)可能是使用一些 WSL or some Linux emulator such as JSLinux (it runs in a web browser). Then you could (painfully) build a cross compiler (starting first with a tinycc-win32, then compiling an old cross GCC 3 compiler, then compiling with that a newer C++ GCC,等等....)

但现实是你不应该被允许这样做。您真正的问题是非技术性的:为什么不允许安装然后使用 C++ 编译器,例如 MinGW?获得安装一些权限(和资源)....

或者,考虑安装一些 Linux distribution(确保您被允许这样做)。他们中的大多数最近 Python 和 GCC...

Is it possible to simply compile+install on another machine and copy it?

这称为 cross-compilation,通常是可能的。关键是要允许这样做。您应该找到适合您情况的相关交叉编译器。

如果允许,您甚至可以使用实时 Linux U 盘....

某些 C 编译器 written in Python do exist.... You could use them to cross-compile tinycc for Win32. Then you should have a C compiler for Win32. You could then compile an old GCC, etc.... Qemu 存在 windows。你可以 运行 Linux 在 Qemu 中使用跨 GCC 编译器。