管道建置因Python無法使用錯誤而失敗

透過建立使用執行外掛程式安裝Python3的Maven專案,修復由於Python錯誤造成的管道建置失敗。

說明 description

環境

AEM as a Cloud Service

問題/症狀

必須安裝Python 3.10版,因為前端程式碼需要Python才能建置應用程式。

但是,在Cloud Manager中部署管道時,建置會失敗,並出現以下錯誤:

[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! configure error
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack   at PythonFinder.fail (/build_root/build/<project>/ui.frontend/node_modules/node-gyp/lib/find-python.js:330:47)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack  at PythonFinder.runChecks (/build_root/build/<project>/ui.frontend/node_modules/node-gyp/lib/find-python.js:159:21)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack at PythonFinder.<anonymous> (/build_root/build/<project>/ui.frontend/node_modules/node-gyp/lib/find-python.js:266:16)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack  at PythonFinder.execFileCallback (/build_root/build/<project>/ui.frontend/node_modules/node-gyp/lib/find-python.js:297:7)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack  at ChildProcess.exithandler (node:child_process:317:7)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack  at ChildProcess.emit (node:events:365:28)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack  at maybeClose (node:internal/child_process:1067:16)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! stack  at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! System Linux 5.10.102.2-microsoft-standard
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! command "/build_root/build/<project>/ui.frontend/node/node" "/build_root/build/<project>/ui.frontend/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! cwd /build_root/build/<project>/ui.frontend/node_modules/node-sass
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! node -v v16.0.0
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! node-gyp -v v8.4.1
[ Exec Stream Pumper]  [ INFO]  npm ERR! gyp ERR! not ok
[ Exec Stream Pumper]  [ INFO]  npm ERR! Build failed with error code: 1
[ Exec Stream Pumper]  [ INFO]
[ Exec Stream Pumper]  [ INFO]  npm ERR! A complete log of this run can be found in:
[ Exec Stream Pumper]  [ INFO]  npm ERR!  /root/.npm/_logs/2023-11-06T17_43_49_109Z-debug.log

在我們的Experience League促銷活動社群中提問

若您有任何關於此主題的疑問或想閱讀之前的已回答問題,請檢視包含本文的Experience League社群部落格,傳送您的問題與意見,並加入我們的Experience League促銷活動社群!

解決方法 resolution

如果未安裝Python,可依照下列步驟安裝Maven:

若要建立使用Exec外掛程式安裝Python3的Maven專案,必須完成pom.xml的設定。

範例:

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>PythonInstaller</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging>
<build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.6.0</version><executions><execution><id>apt-get-update</id><phase>validate</phase><goals><goal>exec</goal></goals><configuration><executable>apt-get</executable><arguments><argument>update</argument></arguments></configuration></execution><execution><id>install-python3</id><phase>validate</phase><goals><goal>exec</goal></goals><configuration><executable>apt-get</executable><arguments><argument>install</argument><argument>-y</argument><argument>python3</argument></arguments></configuration></execution></executions></plugin></plugins></build></project>

Maven設定將在Maven組建生命週期的驗證階段中執行 apt-get 更新和 apt-get install -y python3 命令。 此外,請注意,只有在組建是在有 apt-get 命令可用且正在執行的環境中執行時,這才會運作。 組建必須有足夠許可權才能安裝套件。

同樣地,如果您需要安裝Python 3.11,pom.xml看起來應該像這樣:

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.example</groupId><artifactId>PythonInstaller</artifactId><version>1.0-SNAPSHOT</version><packaging>jar</packaging>
<build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>1.6.0</version><executions><execution><id>apt-get-update</id><phase>validate</phase><goals><goal>exec</goal></goals><configuration><executable>apt-get</executable><arguments><argument>update</argument></arguments></configuration></execution><execution><id>install-python3.11</id><phase>validate</phase><goals><goal>exec</goal></goals><configuration><executable>apt-get</executable><arguments><argument>install</argument><argument>-y</argument><argument>python3.11</argument></arguments></configuration></execution></executions></plugin></plugins></build></project>
recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f