问题
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