0

正如标题所示,我正在使用PytonQt。我已经正确地构建了它(我可以在 Qt Creator 中运行示例),但现在在 Python 本身中使用 PythonQt 时遇到了困难。作为参考,我几乎没有 C++ 经验,或者我无法使用 python 库,所以这整个过程对我来说是新的,我什至不知道我需要咨询什么。我认为构建过程会创建直接导入 python 的必要文件,但我在 PythonQt 文件夹或我的 Python 安装中什么都看不到。不幸的是,关于 PythonQt 的文档非常稀少,对没有这方面经验的人一点帮助都没有,所以我希望有人可以解释构建后的过程。

我正在使用 Python 3.9.6 和 Qt 5.15。我使用来自另一个 stackoverflow 问题的批处理文件构建了代码:

rem Construct python paths
set "pypath=C:\Python39"

set "pylibpath=%pypath%\libs"

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

rem Build PythonQt
call C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Community\VC\Auxiliary\Build\vcvarsall.bat x86 && call C:\Qt6\5.15.2\msvc2019\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 如下:

# profile to include and link Python


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

isEmpty( PYTHON_DIR ) {
  PYTHON_DIR=$$(PYTHON_DIR)
}
!isEmpty( PYTHON_DIR ) {
  PYTHON_DIR=$${PYTHON_DIR}/
}

message(Using Python version $${PYTHON_VERSION})

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.

  PYTHON_CONFIG = $${PYTHON_DIR}/bin/python$${PYTHON_VERSION}-config
  system($${PYTHON_CONFIG} --embed --libs) {
    unix:LIBS += $$system($${PYTHON_CONFIG} --embed --libs)
  } else: unix:LIBS += $$system($${PYTHON_CONFIG} --libs)
  unix:QMAKE_CXXFLAGS += $$system($${PYTHON_CONFIG} --includes)
  PYTHON_LFLAGS = $$system($${PYTHON_CONFIG} --ldflags)
  unix:QMAKE_LFLAGS += $${PYTHON_LFLAGS}
  # add rpath
  PYTHON_LIBDIR = $$find(PYTHON_LFLAGS,-L.*)
  RPATH = -Wl,-rpath,
  PYTHON_RPATH = $$replace(PYTHON_LIBDIR,-L,$${RPATH})
  unix:QMAKE_LFLAGS += $${PYTHON_RPATH}
}

如果有人可以提供帮助,请提前感谢您。

4

0 回答 0