Enable Python scripting for Windows builds
Closed, ResolvedPublic

Description

Figure out how to have it working, and how to package it for release.

Targeting Qt 5.9.1.

Related Objects

alvinhochun raised the priority of this task from Normal to High.Jul 14 2017, 7:14 PM
alvinhochun updated the task description. (Show Details)

I managed to build Krita on Windows with sip and pyqt after a lot of changes (might push them on a temporary branch). I used a local install of python 3.6.1 but I'll need to use the one in 3rdparty at a later time...

The first thing Krita spits out is:

krita.scripting: Could not load C:/Python36/libs/libpython36.a

("F:\dev\krita\new\src\plugins\extensions\pykrita\plugin\utilities.cpp" line 176)
Trying to load the import lib is obviously not going to work. It's not a DLL.

It's from the PYTHON_LIBRARY var set by FindPythonLibrary.cmake which calls find_package(PythonLibs)

Also, isn't the plugin supposed to have already been linked to python36.dll? That's what the .a file supposed to do, right? I think that whole loading part can be removed.

Next up I have

~~~
[8484] krita.scripting: "Traceback (most recent call last):"
[8484] krita.scripting: " File \"F:/dev/krita/new/build_x64/install/share/krita/pykrita\\krita\\__init__.py\", line 8, in <module>"
[8484] krita.scripting: " from .api import *"
[8484] krita.scripting: " File \"F:/dev/krita/new/build_x64/install/share/krita/pykrita\\krita\\api.py\", line 28, in <module>"
[8484] krita.scripting: " from PyKrita.krita import *"
[8484] krita.scripting: "ModuleNotFoundError: No module named 'PyKrita.krita'"
[8484] krita.scripting: "Could not import krita"
~~~

which is a bit interesting, because if I check install\share\krita\pykrita there is a folder named PyKrita and inside it there is a krita.dll.
Is this DLL what the script tried to import? Or is it supposed to be another python script?

I pushed my temporary changes to the branch alvin/T6503-winpython-temp

alvinhochun added a comment.EditedJul 15 2017, 5:57 PM

I think I'll need this setup...

  1. ext_python should download an embeddable version of python 3.6.1 and extract it to CMAKE_INSTALL_PREFIX/python
  2. In order to have the proper import library and headers, the build host system should also have the same version of python 3.6.1 installed (even the architecture must match, so when building for 64-bit windows you need to build on 64-bit windows or otherwise you can't even run python.exe at all unless with some hacks). The correct python version must be on PATH. I'll try to add additional cmake checks for that.
  3. The pykrita plugin needs to be able to load python36.dll. I think it is a bad idea to just put the embeddable python under bin/ because it would cause even more cluttering. Instead, I would add additional logic to load the DLL from python/ before loading the pykrita plugin.
alvinhochun added a comment.EditedJul 16 2017, 6:47 PM

Managed to eliminate the errors on the debug output. Tools->Scripts shows an empty list though...

PyKrita/krita.dll needs to be renamed as .pyd

Can anyone on Linux try cherry-picking commit R37:2722cbe1bfb9 and check whether python still works?

Looks like I've got the scripts to load. I'll start tidying up some patches for the simpler changes.

Still need to figure out how to deploy and package the python files and have it run on Windows nicely without needing user configuration.

As of d81740abfb333c9daf13254cd89deb57b34e320c, the build instructions for 3rdparty/ should be changed as below:

  1. Use mingw-w64 7.1.
  2. Use latest CMake 3.8, CMake 3.9 does *not* work according to boud.
  3. Host should have Python 3.6.2 installed (though any 3.6 should work fine), architecture must match the build target. It should appear in PATH.
  4. After building the existing stated targets, build ext_sip and then ext_pyqt. (ext_python isn't being used atm.)

After that, build Krita as usual. Make sure SIP and PyQt are found during the configuration step.

TODO: Update the README

As of 6332f0dadacee404d6acd56abfd27bd9e65bc4b6, it can load the embedded Python if python3.dll *and* python36.dll are copied into bin/.

Updated the packaging script and instructions, all on branch alvin/T6503-python-win.

alvinhochun closed this task as Resolved.Jul 29 2017, 7:30 AM