1

我正在尝试为我在 Windows 上构建的 Qt 5.12 应用程序安装 PythonQt。不幸的是,文档非常稀少,我完全不熟悉在我的代码中使用外部库,或者根本不熟悉构建项目。

所以,我想我很接近了。我有一个批处理脚本,我认为它实际上构建了 PythonQt。这给我留下了一些 dll、exp 文件和 lib 文件。基于我正在构建的 python 版本,一些变体被命名为 PythonQt_QtAll-Qt5-Python38,而一些变体被命名为 PythonQt-Qt5-Python38。我不知道它们之间的区别是什么,因为文档不清楚。

我不知道从哪里开始,我尝试按照此链接中的说明进行操作:https ://doc.qt.io/qtcreator/creator-project-qmake-libraries.html ,但我似乎没有要包含的任何头文件。我很确定我不应该只是将随机头文件从 PythonQt 源中取出并放入我的应用程序中。

这是我的批处理文件,我认为它正在工作,但没有什么是确定的:

rem Take current dir
set "crt_dir=%~dp0"

rem Go up one level
for %%I in ("%crt_dir%\..") do set "root=%%~fI"

rem Construct python paths
set "pypath=%root%\Python38-32"
set "pylibpath=%pypath%\libs"

rem Set PYTHON_PATH environmental variable permanently
setx PYTHON_PATH %pypath%
setx PYTHON_LIB %pylibpath%
setx PYTHON_VERSION 38

rem Build PythonQt
rem Fairly sure this is the same command as vcvars32.bat
rem https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=vs-2019
call C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Community\VC\Auxiliary\Build\vcvarsall.bat x86 && call c:\Qt\5.12.2\msvc2017\bin\qmake && call C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\nmake /f Makefile || echo Build of PythonQt failed, Exit Code is %errorlevel% 

cmd /k

这是我的 python.prf 文件:

# Change this variable to your python version (2.6, 2.7, 3.3, ...)
PYTHON_VERSION=$$(PYTHON_VERSION)
isEmpty( PYTHON_VERSION ) {
  win32:PYTHON_VERSION=38
  unix:PYTHON_VERSION=3.8
}


macx {
  # for macx you need to have the Python development kit installed as framework
  INCLUDEPATH += /System/Library/Frameworks/Python.framework/Headers
  LIBS += -F/System/Library/Frameworks -framework Python
} else:win32 {
  # for windows install a Python development kit or build Python yourself from the sources
  # Make sure that you set the environment variable PYTHON_PATH to point to your
  # python installation (or the python sources/header files when building from source).
  # Make sure that you set the environment variable PYTHON_LIB to point to
  # the directory where the python libs are located.
  #
  # When using the prebuild Python installer, this will be:
  # set PYTHON_PATH = c:\Python26
  # set PYTHON_LIB  = c:\Python26\libs
  #
  # When using the python sources, this will be something like:
  # set PYTHON_PATH = c:\yourDir\Python-2.6.1\
  # set PYTHON_LIB  = c:\yourDir\Python-2.6.1\PCbuild8\Win32

  # check if debug or release
  CONFIG(debug, debug|release) {
    DEBUG_EXT = #_d 
  } else {
    DEBUG_EXT = 
  }

  win32:INCLUDEPATH += $$(PYTHON_PATH)/PC $$(PYTHON_PATH)/include
  win32:LIBS += $$(PYTHON_LIB)/python$${PYTHON_VERSION}$${DEBUG_EXT}.lib
} else:unix {
  # on linux, python-config is used to autodetect Python.
  # make sure that you have installed a matching python-dev package.

  unix:LIBS += $$system(python$${PYTHON_VERSION}-config --ldflags)
  unix:QMAKE_CXXFLAGS += $$system(python$${PYTHON_VERSION}-config --includes)
}

还有我的 common.prf:

# depending on your Qt configuration, you want to enable or disable
# one of the release/debug builds (if all three lines are commented,
# the default of your Qt installation will used)

# build with both debug and release mode
#CONFIG += debug_and_release build_all

# build with release mode only
#CONFIG += release

# build with debug mode only
#CONFIG += debug

# for all debug builds, add "_d" extension to target
CONFIG(debug, debug|release) {
  TARGET = $${TARGET}_d 
}

# Try files that are generated by the user:
PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp

!exists($$PYTHONQT_GENERATED_PATH) {
  # If no files are generated, try the checked-in wrappers:
  PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_$${QT_MAJOR_VERSION}$${QT_MINOR_VERSION}

  !exists($$PYTHONQT_GENERATED_PATH) {
    contains( QT_MAJOR_VERSION, 5 ) {
      contains( QT_MINOR_VERSION, 10 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_56
      }
      else:contains( QT_MINOR_VERSION, 11 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_511
      }
      else:contains( QT_MINOR_VERSION, 12 ) {
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_511
      }
      else:contains( QT_MINOR_VERSION, 1 ) {
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_50
      }
      else:contains( QT_MINOR_VERSION, 2 ) {
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_50
      }
      else:contains( QT_MINOR_VERSION, 3 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_53
      }
      else:contains( QT_MINOR_VERSION, 4 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_54
      }
      else:contains( QT_MINOR_VERSION, 5 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_54
      }
      else:contains( QT_MINOR_VERSION, 6 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_56
      }
      else:contains( QT_MINOR_VERSION, 7 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_56
      }
      else:contains( QT_MINOR_VERSION, 8 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_56
      }
      else:contains( QT_MINOR_VERSION, 9 ) { 
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_56
      }
      else {
        PYTHONQT_GENERATED_PATH = $$PWD/../generated_cpp_56
      }
    }
  }
}

VERSION = 3.2.0

# Suppress the automatic version number appended to the DLL file name on Windows.
win32: CONFIG += skip_target_version_ext

总之,我相信我已经构建了 PythonQt,并且我有一堆用于 PythonQt 示例项目的可执行文件,以及分别用于 PythonQt-Qt5-Python38 和 PythonQt_QtAll-Qt5-Python38 的 dll、exp 和 lib 文件。我从这里去哪里?

4

1 回答 1

1

答案一直在例子中。构建 PythonQt 后,您只需在项目的 .pro 文件中包含所有相关的 .prf 文件,例如:

include ( ./third_party/PythonQt/build/common.prf )  
include ( ./third_party/PythonQt/build/PythonQt.prf )  
include ( ./third_party/PythonQt/build/PythonQt_QtAll.prf )  

仍然欢迎有关如何将 PythonQt 编译到库中的任何答案,但我最初的问题已经解决。

于 2019-11-10T20:05:56.127 回答