xlwings UDFS: how to set PythonPath/ UDF_Modules correctly?

爱⌒轻易说出口 提交于 2019-12-06 13:16:45

问题


Thank you for your time first!

Recently I have been trying to build my own excel functions by using Xlwings. Unlike using

$ xlwings quickstart myproject 

which would create a python script in the same directory as the excel xlsm file, I would love to put the python script anywhere I want, like "D:\test0.py", so I did this on VBA Function Settings:

PYTHONPATH = "D:\test0.py"
UDF_MODULES = "test0"

Except the two lines above, I didn't change anything in Function Settings. However, what I got is only: errors, No module named 'test0'

I am now fully confused, what should I do if I want to import module from "D:\test0.py" correctly? I know this might be a stupid question, but I really need help now.

Thanks again!


回答1:


PYTHONPATH, as the name says, is a path, not a file, i.e. you should be using

PYTHONPATH = "D:\"

xlwings quickstart myproject is still useful because it sets up the Excel file with the VBA module, even if you want to move out the python file later on.




回答2:


Yes, I'm new to Python / xlwings, but I hadn't realised how precise I needed to be. Had to set the Interpreter to C:\Anaconda3\pythonw.exe and PYTHONPATH to C:\\Anaconda3 and both the UDFs and RunPython VBA calls started working.



来源:https://stackoverflow.com/questions/38983144/xlwings-udfs-how-to-set-pythonpath-udf-modules-correctly

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