RunPython Usage

霸气de小男生 提交于 2020-03-06 06:36:00

问题


I am attempting to run a python script from excel and am using a vba function to achieve this. I am using xlwings but am getting an error message:

'python' is not recognized as an internal or external command, operable program or batch file.

This occurs when running the following code:

RunPython ("import MarketVolume; MarketVolume.market_volume()")

Thanks in advance, Max


回答1:


You either need to add python to your PATH so that you can start it by typing python on the command prompt or you need to set the full path to the python.exe in your add-in or vba settings for your Interpreter, see http://docs.xlwings.org/en/stable/addin.html#global-settings, see also: http://docs.xlwings.org/en/stable/troubleshooting.html




回答2:


Be sure you have either the xlwings module present in your VBA project(File->Import File-> xlwings.bas under the main xlwings directory) or you have the xlwings add-in installed(xlwings addin install on the command line) and the reference to xlwings set in your VBA project(Tools->References). Then, as Felix said, point your VBA project to your python installation. If you are using the add-in, under 'Interpreter' paste the path to pythonw.exe including the filename. If you are using the module, put the same information next to PYTHONWIN or PYTHONMAC in the config area of the file depending on which OS you're running. As stated in the xlwings documentation, it is preferable to use the add-in over the module, mainly because it makes it a lot easier to manage UDFs.



来源:https://stackoverflow.com/questions/45331563/runpython-usage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!