如何将 Python3 安装的 VTK 包含到 setup.py 中?
How to include VTK for Python3 installation into setup.py?
无法通过 pip
安装 VTK 库。
不过,它可以从源代码编译和安装。
我的 Python 项目依赖于 VTK。
我希望它通过从项目的根目录调用 pip install .
来自动安装 VTK。
在这种情况下 setup.py
文件应该能够
- 从GitHub
下载所需版本的VTK源
- 调用
cmake
以准备构建
- 编译源代码并创建 Python 绑定
- 将需要的文件安装到当前使用的
site-packages
中(例如,如果我使用 virtualenv
、pipenv
或 pyenv
,则不应将其安装到 /usr/local/lib/python3/site-packages
中)
可能吗?
如果是,我该怎么做?
原则上,您可以在安装文件中包含任何可执行代码。但是,我在 setuptools documentation 的任何地方都找不到可以解决这里问题的信息。
此外,vtk 的安装过程有点复杂,这就是 kitware 首先使用 cmake 的原因。
所以,简短的回答是 "no" 或 "don't do that"。
另外,您会遇到的问题:
用户会期望透明安装。但是在 vtk 的 cmake 构建指令的基础上实现跨平台构建过程将阻止您设置自定义(vtk 路径、Python 解释器路径、平台特定的 C 标志)。
安装过程将更难调试。用户会来找你解决 VTK 构建问题。
Kitware本身不建议在pypi上使用vtk。这表明要实现此目标需要花费太多时间、不可能或太脆弱。
如果您希望查看依赖于 vtk 的流行 Python 项目,可以使用 mayavi。 installation instructions 请求预先安装 vtk。
看起来 VTK 已经通过 pypi 展示了他们的 official binding,所以我可以在 setup.py
文件中使用它,只需将它附加到 install_requires
列表即可。
在我的项目中运行良好,不再需要编译。
中有一个警告
The latest VTK wheels are available on all the major platforms
(Windows, MacOS, and Linux), but only for 64 bit machines. Python 3.x
is fully supported on all these operating systems and Python 2.7.x on
MacOS and Linux. If you are out of luck, and your platform is not
supported then you will need to install VTK yourself using your
particular distribution as discussed in the General Build and
Installation instructions
无法通过 pip
安装 VTK 库。
不过,它可以从源代码编译和安装。
我的 Python 项目依赖于 VTK。
我希望它通过从项目的根目录调用 pip install .
来自动安装 VTK。
在这种情况下 setup.py
文件应该能够
- 从GitHub 下载所需版本的VTK源
- 调用
cmake
以准备构建 - 编译源代码并创建 Python 绑定
- 将需要的文件安装到当前使用的
site-packages
中(例如,如果我使用virtualenv
、pipenv
或pyenv
,则不应将其安装到/usr/local/lib/python3/site-packages
中)
可能吗? 如果是,我该怎么做?
原则上,您可以在安装文件中包含任何可执行代码。但是,我在 setuptools documentation 的任何地方都找不到可以解决这里问题的信息。
此外,vtk 的安装过程有点复杂,这就是 kitware 首先使用 cmake 的原因。
所以,简短的回答是 "no" 或 "don't do that"。
另外,您会遇到的问题:
用户会期望透明安装。但是在 vtk 的 cmake 构建指令的基础上实现跨平台构建过程将阻止您设置自定义(vtk 路径、Python 解释器路径、平台特定的 C 标志)。
安装过程将更难调试。用户会来找你解决 VTK 构建问题。
Kitware本身不建议在pypi上使用vtk。这表明要实现此目标需要花费太多时间、不可能或太脆弱。
如果您希望查看依赖于 vtk 的流行 Python 项目,可以使用 mayavi。 installation instructions 请求预先安装 vtk。
看起来 VTK 已经通过 pypi 展示了他们的 official binding,所以我可以在 setup.py
文件中使用它,只需将它附加到 install_requires
列表即可。
在我的项目中运行良好,不再需要编译。
The latest VTK wheels are available on all the major platforms (Windows, MacOS, and Linux), but only for 64 bit machines. Python 3.x is fully supported on all these operating systems and Python 2.7.x on MacOS and Linux. If you are out of luck, and your platform is not supported then you will need to install VTK yourself using your particular distribution as discussed in the General Build and Installation instructions