【发布时间】:2022-01-05 23:48:16
【问题描述】:
运行以下python代码 使用命令 python3 在 vscode 和终端中完全可以正常工作
import sys as sys
import pandas as ps
import os
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
print("PATH:", os.environ.get('PATH'))
print('testing...')
sys.stdout.flush()
但是当我尝试使用节点 child_process 运行它时 使用以下代码:
const {spawn,exec} = require('child_process')
const pyProcess = spawn('python3',['./python/test.py']);
var result = ''
pyProcess.stdout.on('data',(data) => result += data.toString())
pyProcess.stdout.on('end',() => console.log(result))
pyProcess.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
它返回这个包导入错误:
stderr: import pandas as ps
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3"
* The NumPy version is: "1.22.0"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/lib/_multiarray_umath.cpython-310-darwin.so' (no such file)
**注意:此错误仅在 Mac OS m1 芯片设备上运行时出现, 适用于 Windows pc **
【问题讨论】:
-
您仔细研究了上面链接的文档吗?
-
是的,没有帮助。
标签: python node.js python-3.x numpy child-process