6、部署常见问题
部署常见问题
版权声明
注意
本着开源共享、共同学习的精神:
本文是记录了 博主Ruyu 开源项目:《Ruyu-Blog 》https://gitee.com/kuailemao/ruyu-blog 部署&使用过程得一些细节,转载无需和我联系,但请注明文章来源。如果侵权之处,请联系博主进行删除,谢谢~
强烈推荐:
博主Ruyu :
Ruyu-Blog开源博客gitee地址:https://gitee.com/kuailemao/ruyu-blog
Ruyu-Blog开源博客网站地址:https://www.kuailemao.xyz/
案例:前端前台构建需要依赖python3环境-2024.8.16(已解决)
1、报错现象
[root@localhost kuailemao-blog]# pnpm install
Lockfile is up to date, resolution step is skipped
Packages: +742
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
╭─────────────────────────────────────────────────────────────────╮
│ │
│ Update available! 8.12.0 → 9.7.1. │
│ Changelog: https://github.com/pnpm/pnpm/releases/tag/v9.7.1 │
│ Run "pnpm add -g pnpm" to update. │
│ │
│ Follow @pnpmjs for updates: https://twitter.com/pnpmjs │
│ │
╰─────────────────────────────────────────────────────────────────╯
Downloading mirrors.huaweicloud.com/element-plus/2.7.6: 8.71 MB/8.71 MB, done
Downloading mirrors.huaweicloud.com/echarts/5.5.1: 10.36 MB/10.36 MB, done
Progress: resolved 742, reused 0, downloaded 742, added 742, done
node_modules/.pnpm/vue-demi@0.14.8_vue@3.4.31/node_modules/vue-demi: Running postinstall script, done in 220ms
node_modules/.pnpm/esbuild@0.18.20/node_modules/esbuild: Running postinstall script, done in 101ms
node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass: Running install script, done in 22s
node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass: Running postinstall script, failed in 301ms
.../node_modules/node-sass postinstall$ node scripts/build.js
│ Building: /usr/local/nodejs/bin/node /root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= -…
│ gyp info it worked if it ends with ok
│ gyp verb cli [
│ gyp verb cli '/usr/local/nodejs/bin/node',
│ gyp verb cli '/root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/bin/node-gyp.js',
│ gyp verb cli 'rebuild',
│ gyp verb cli '--verbose',
│ gyp verb cli '--libsass_ext=',
│ gyp verb cli '--libsass_cflags=',
│ gyp verb cli '--libsass_ldflags=',
│ gyp verb cli '--libsass_library='
│ gyp verb cli ]
│ gyp info using node-gyp@8.4.1
│ gyp info using node@16.20.2 | linux | x64
│ gyp verb command rebuild []
│ gyp verb command clean []
│ gyp verb clean removing "build" directory
│ gyp verb command configure []
│ gyp verb find Python Python is not set from command line or npm configuration
│ gyp verb find Python Python is not set from environment variable PYTHON
│ gyp verb find Python checking if "python3" can be used
│ gyp verb find Python - executing "python3" to get executable path
│ gyp verb find Python - "python3" is not in PATH or produced an error
│ gyp verb find Python checking if "python" can be used
│ gyp verb find Python - executing "python" to get executable path
│ gyp verb find Python - executable path is "/usr/bin/python"
│ gyp verb find Python - executing "/usr/bin/python" to get version
│ gyp verb find Python - version is "2.7.5"
│ gyp verb find Python - version is 2.7.5 - should be >=3.6.0
│ gyp verb find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
│ gyp ERR! find Python
│ gyp ERR! find Python Python is not set from command line or npm configuration
│ gyp ERR! find Python Python is not set from environment variable PYTHON
│ gyp ERR! find Python checking if "python3" can be used
│ gyp ERR! find Python - "python3" is not in PATH or produced an error
│ gyp ERR! find Python checking if "python" can be used
│ gyp ERR! find Python - executable path is "/usr/bin/python"
│ gyp ERR! find Python - version is "2.7.5"
│ gyp ERR! find Python - version is 2.7.5 - should be >=3.6.0
│ gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
│ gyp ERR! find Python
│ gyp ERR! find Python **********************************************************
│ gyp ERR! find Python You need to install the latest version of Python.
│ gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
│ gyp ERR! find Python you can try one of the following options:
│ gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
│ gyp ERR! find Python (accepted by both node-gyp and npm)
│ gyp ERR! find Python - Set the environment variable PYTHON
│ gyp ERR! find Python - Set the npm configuration variable python:
│ gyp ERR! find Python npm config set python "/path/to/pythonexecutable"
│ gyp ERR! find Python For more information consult the documentation at:
│ gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
│ gyp ERR! find Python **********************************************************
│ gyp ERR! find Python
│ gyp ERR! configure error
│ gyp ERR! stack Error: Could not find any Python installation to use
│ gyp ERR! stack at PythonFinder.fail (/root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/lib/find-python.js:330:47)
│ gyp ERR! stack at PythonFinder.runChecks (/root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/lib/find-python.js:159:21)
│ gyp ERR! stack at PythonFinder.<anonymous> (/root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/lib/find-python.js:266:16)
│ gyp ERR! stack at PythonFinder.execFileCallback (/root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/lib/find-python.js:297:7)
│ gyp ERR! stack at ChildProcess.exithandler (node:child_process:394:7)
│ gyp ERR! stack at ChildProcess.emit (node:events:513:28)
│ gyp ERR! stack at maybeClose (node:internal/child_process:1100:16)
│ gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
│ gyp ERR! System Linux 3.10.0-957.el7.x86_64
│ gyp ERR! command "/usr/local/nodejs/bin/node" "/root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-gyp@8.4.1/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "…
│ gyp ERR! cwd /root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass
│ gyp ERR! node -v v16.20.2
│ gyp ERR! node-gyp -v v8.4.1
│ gyp ERR! not ok
│ Build failed with error code: 1
└─ Failed in 301ms at /root/ruyu-blog/blog-frontend/kuailemao-blog/node_modules/.pnpm/node-sass@9.0.0/node_modules/node-sass
ELIFECYCLE Command failed with exit code 1.
[root@localhost kuailemao-blog]#
这个如何解决呢?
2、解决办法
gpt回答
根据你提供的错误信息,node-gyp
找不到合适的 Python 版本。它找到的 Python 版本是 2.7.5,而 node-gyp
需要 Python 3.6 或更高版本。以下是解决此问题的步骤:
- 安装 Python 3
首先,你需要在系统中安装 Python 3。如果你的系统已经安装了 Python 3,请确保它在 PATH
中。
在 CentOS 或 RHEL 系统上,你可以使用以下命令安装 Python 3:
sudo yum -y install python3 --disablerepo=epel
- 设置
PYTHON
环境变量
安装 Python 3 之后,设置 PYTHON
环境变量以指向 Python 3 可执行文件。
export PYTHON=$(which python3)
- 配置 npm 使用 Python 3
你还可以配置 npm 以使用 Python 3:
npm config set python $(which python3)
pnpm config set python $(which python3)
- 重试
pnpm install
现在重新运行 pnpm install
:
pnpm install
- 验证安装
如果问题仍然存在,确保你的 python3
确实在 PATH
中并可以正确执行:
python3 --version
你应该看到类似于 Python 3.x.x
的输出(确保版本是 3.6 或更高)。
总结
通过以上步骤,你应该能解决 node-gyp
找不到合适 Python 版本的问题。确保 Python 3 安装并配置正确后,pnpm install
应该能顺利完成。
如果还有问题,可以检查以下几点:
- 确认
python3
是否在PATH
中,可以通过which python3
来验证路径。 - 确认 npm 配置正确,可以通过
npm config get python
来查看配置。