简体   繁体   中英

xlwings doesn't recognize imported module openturns

I set up a spreadsheet tool with Python scripts using xlwings. So far so good and everything works fine, I'm running it from Anaconda using Spyder. I can run the script from Excel (using the VBA connection) and from Python, both are working fine.

Now I'm trying to improve it for which I'm using functions from the OpenTURNS module. So I added the line: import openturns as ot . OpenTURNS is installed correctly as I can use its functions in Spyder.

From Spyder I can run the script and write results to Excel, BUT if I run it from Excel I get the error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "DecisionTool.py", line 12, in main
    import openturns as ot
ImportError: No module named openturns

So for some reason, while Spyder can find the openturns module, if I do exactly the same thing and run it from Excel it can't find it. Considering that I can still run everything from Spyder it should be some error in the connection between Excel and Python. However, as I understood, VBA calls python after which Python takes over, so I don't have any clue where to look. Hope anyone can help.

When you excute Python code through the xlwings VBA module, the default Python interpreter is started, ie the same as if you type python at the command prompt. So the first thing to check is what happens if you start python at the command prompt and try to import openturns . If it can't find it, then Spyder is either using another Python installation or Spyder is somewhere adding the path to the openturns installation.

If Spyder uses a different installation than your default, you can either change the default or set the path to the interpreter in the VBA module, as explained here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM