通过Pentaho运行python脚本

2024-05-12 19:29:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试使用Pentaho运行python脚本时遇到了麻烦。我有一个测试脚本,它读取csv,添加一个新列,然后将一个新的csv写入我的目标目录

我正在使用“脚本”下拉列表下的“shell”作业。 我选中了“常规”选项卡上的“插入脚本”选项,并插入了这个脚本

"C:\\Anaconda3\\pythonw.exe" 
"C:\Users\mike\Documents\mike\Pentaho_Test_Aug16.py"  

进入“脚本”选项卡

当我在spyder中运行sys.executable时,我得到了这个,这就是我在python.exe位置上使用的

 'C:\\Anaconda3\\pythonw.exe'

当我在Pentaho中运行该进程时,它会在日志文件中返回:

2021/08/16 14:13:10 - Spoon - Starting job...
2021/08/16 14:13:10 - Pentaho Test with Python - Start of job execution
2021/08/16 14:13:10 - Pentaho Test with Python - Starting entry [Shell]
2021/08/16 14:13:10 - Shell - Running on platform : Windows Server 2016
2021/08/16 14:13:10 - Shell - Executing command : cmd.exe /C "C:\Users\MICHAE~1\AppData\Local\Temp\19\kettle_9d3125e0-febd-11eb-aa51-37d1ddb117e6shell.bat"
2021/08/16 14:13:10 - Shell - (stdout)
2021/08/16 14:13:10 - Shell - (stdout) C:\data-integration>"C:\\Anaconda3\\pythonw.exe" "C:\Users\mike\Documents\mike\Pentaho_Test_Aug16.py"
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) C:\Anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)   from . import _distributor_init
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) Traceback (most recent call last):
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)   File "C:\Users\mike\Documents\mike\Pentaho_Test_Aug16.py", line 2, in <module>
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)     import pandas as pd
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)   File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)     "Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) ImportError: Unable to import required dependencies:
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) numpy:
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) Importing the numpy c-extensions failed.
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) - Try uninstalling and reinstalling numpy.
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) - If you have already done that, then:
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)   1. Check that you expected to use Python3.7 from "C:\Anaconda3\pythonw.exe",
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      and that you have no directories in your PATH or PYTHONPATH that can
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      interfere with the Python and numpy version "1.18.1" you're trying to use.
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)   2. If (1) looks fine, you can open a new issue at
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      https://github.com/numpy/numpy/issues.  Please include details on:
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      - how you installed Python
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      - how you installed numpy
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      - your operating system
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      - whether or not you have multiple versions of Python installed
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)      - if you built from source, your compiler versions and ideally a build log
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) - If you're working with a numpy git repository, try `git clean -xdf`
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)   (removes all files not under version control) and rebuild numpy.
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) Note: this error has many possible causes, so please don't comment on
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) an existing issue about this - open a new one instead.
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr) Original error was: DLL load failed: The specified module could not be found.
2021/08/16 14:13:10 - Shell - ERROR (version 8.1.0.0-365, build 8.1.0.0-365 from 2018-04-30 09.42.24 by buildguy) : (stderr)
2021/08/16 14:13:10 - Pentaho Test with Python - Finished job entry [Shell] (result=[false])
2021/08/16 14:13:10 - Pentaho Test with Python - Job execution finished
2021/08/16 14:13:10 - Spoon - Job has ended.
2021/08/16 14:13:31 - Spoon - Spoon
2021/08/16 14:13:48 - Spoon - Spoon

非常感谢您的帮助

此外,当我在Spyder中运行它时,该代码可以工作,但当我试图通过Pentaho运行它时,它失败了

如果你想知道我想做什么,youtube上的这个家伙正在做我想做的事。我是根据他所做的事来采取我的方法的

https://www.youtube.com/watch?v=sN-MNRitfrA

不知道?有人吗

提前谢谢

更新:

按照下面Dirk的建议,我添加了命令以附加必要的mlk_u3;的位置。。。将文件添加到系统路径变量。在“执行shell脚本…”对话框中输入以下内容解决了我的问题:

set PATH=%PATH%;C:\Anaconda3\Library\bin
"C:\\Anaconda3\\pythonw.exe" 
"C:\Users\mike\Documents\mike\Pentaho_Test_Aug16.py" 

Tags: fromtestbuildnumpy脚本youbyversion