简体   繁体   中英

How to include VTK for Python3 installation into setup.py?

VTK library cannot be installed via pip . Though, it can be compiled and installed from sources.

My Python project depends on VTK. I want it to install VTK automatically by calling pip install . from root directory of the project. In this case setup.py file should be able to

  • download VTK sources of needed version from GitHub
  • call cmake in order to prepare build
  • compile sources and create Python bindings
  • install needed files into currently used site-packages (eg, it should not be installed into /usr/local/lib/python3/site-packages if I use virtualenv , pipenv or pyenv )

Is it possible? If yes, how can I do this?

In principle, you can include any executable code in the setup file. However, nowhere in the setuptools documentation could I find information that would solve the problem here.

Also, the installation procedure for vtk is a bit complex which is why kitware uses cmake in the first place.

So, the short answer would be "no" or "don't do that".

Further, the problems you will encounter:

  1. Users will expect a transparent install. But achieving a cross-platform build process on the basis of the cmake build instructions for vtk will prevent you from setting the customization (path to vtk, path to the Python interpreter, platform-specific C flags).

  2. The install process will be harder to debug. Users will come to you for VTK build problems.

  3. Kitware themselve do not propose vtk on pypi. This suggests that it is too much time intensive, impossible or too fragile to maintain to achieve this goal.

If you wish to see a popular Python project that relies on vtk, there is mayavi. The installation instructions request to install vtk beforehand.

Looks like VTK has presented their official binding via pypi, so I can use it in setup.py file simply by appending it to install_requires list. Works well in my project, doesn't need compilation anymore.

Though, there is a caution in the mayavi documentation

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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