繁体   English   中英

Cmake似乎不使用它确认已使用的Python解释器

[英]Cmake seems not to use the Python interpreter it confirms it uses

我有以下CMakeLists.txt文件,该文件指示使用Python 4.4

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/../cmake/")

project(aConfigd VERSION 1.0)
string(TOLOWER aConfigd project_id)

find_package(PythonInterp 3.4 REQUIRED)

include(FindPythonInterp)
set(PYTHON ${PYTHON_EXECUTABLE})
message(STATUS "\${PYTHON_EXECUTABLE} == ${PYTHON_EXECUTABLE}")
set(pkgdatadir /usr/share/configd)
set(configdir /etc/amy)
set(SONARCONFIGID_SOURCE_DIR etc/configd)
set(SRC_DIR configd/src/)

include(common)
#        "${SRC_DIR}/systemd_client.py"
#        "${SRC_DIR}/amyconfig_service.py"
        "${SRC_DIR}/__init__.py"
        "${SRC_DIR}/main.py"
        "${SRC_DIR}/application.py"
        DESTINATION ${pkgdatadir}/configd/
)

#general
set(CPACK_PACKAGE_NAME "a-config")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "a-config-manager")
set(CPACK_PACKAGE_DESCRIPTION "a-config-manager")

# redhat
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION 
      /etc/amy
      )

include(cpack)

实际上,它确认${PYTHON_EXECUTABLE} == /usr/bin/python3.4 (请参见下面的第4行):

$ make clean ; cmake -DCMAKE_BUILD_TYPE=Release -DSHORT_VERSION=NO -DCUSTOMER=NO .. ;  make -j12 ; make package
-- Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4.5", minimum required is "3.4") 
-- Found PythonInterp: /usr/bin/python3.4 (found version "3.4.5") 
-- ${PYTHON_EXECUTABLE} == /usr/bin/python3.4
-- Build Type: Release
-- Detected distribution: rhel fedora
-- Detected aConfigd version: 2.3.0-3030-gf7733cf659
-- Detected distribution: rhel fedora
-- Configuring done
-- Generating done
-- Build files have been written to: /local/raid0/git/amy/aConfig/build
Run CPack packaging tool...
CPack: Create package using RPM
CPack: Install projects
CPack: - Run preinstall target for: aConfigd
CPack: - Install project: aConfigd
CPack: Create package
CPackRPM:Warning: CPACK_SET_DESTDIR is set (=ON) while requesting a relocatable package (CPACK_RPM_PACKAGE_RELOCATABLE is set): this is not supported, the package won't be relocatable.
CPackRPM: Will use GENERATED spec file: /local/raid0/git/my/aConfig/build/_CPack_Packages/Linux/RPM/SPECS/a-config.spec
CPack: - package: /local/raid0/git/my/aConfig/build/a-config-2.3.0-3030-gf7733cf659.el7.my.x86_64.rpm generated.
$ 

但是,如果取消注释"${SRC_DIR}/systemd_client.py"行, "${SRC_DIR}/systemd_client.py"收到错误消息:

Compiling /local/raid0/git/my/aConfig/build/_CPack_Packages/Linux/RPM/a-config-2.3.0-3030-gf7733cf659.el7.my.x86_64/usr/share/configd/configd/systemd_client.py ...
  File "/usr/share/configd/configd/systemd_client.py", line 21
    def __init__(self, systemd_proxy:Gio.DBusProxy):
                                    ^
SyntaxError: invalid syntax

def __init__(self, systemd_proxy:Gio.DBusProxy): a valid Python 3.4语法吗?
如果是,为什么Cmake会抱怨?

当您只运行"${SRC_DIR}/systemd_client.py" ,您在告诉它以与Shell相同的方式运行该脚本:查看#! 行并使用在那里指定的任何解释器运行它。 大概是#! /usr/bin/python #! /usr/bin/python#! /usr/bin/env python #! /usr/bin/env python

如果要使用特定的解释程序运行脚本,则必须运行该解释程序并将脚本传递给脚本,就像在shell上一样。 我对CMake感到非常生疏,但我假设您是这样的:

"${PYTHON_EXECUTABLE}" "${SRC_DIR}/amyconfig_service.py"

另外,由于这是您的代码,也许您想使用setuptools以编程方式为您的入口点生成脚本,这意味着它将创建一个#! 为他们运行的代码行,无论使用哪个Python版本运行setup.py

根本原因发生在rpmbuild步骤中。
RPM试图提供额外的帮助,并尝试(字节码)编译遇到的.py文件。
,它错误地使用python2解释器来创建文件的字节码(即使在CMakeLists.txt文件中声明了find_package(PythonInterp 3.4 REQUIRED) )。

对我有用的解决方法是:

set(CPACK_RPM_BUILDREQUIRES python34-devel)
set(CPACK_RPM_SPEC_MORE_DEFINE "%define __python ${PYTHON_EXECUTABLE}")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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