1

I am using xlwings to write and read data from Excel files using python 3.4 (Anaconda package). I installed xlwings with

pip install xlwings

Update: I realized that I might not have given enough info about what I am trying to do. So here it is: I am writing my code in the editor called Spyder. What I usually do is, I put the "import commands" at the beginning of my code. However, when I run the code, the "import command" for xlwings would not work and gives me the "ImportError" I am taking about below. Interestingly, what I found out later: if I save the code (my program) in my home directory it will execute the import command without problems. I also have no problems if I import xlwings in the python console in my spyder editor (which is again home directory), which then allows me to run my code even if is is not saved in my home directory. I am puzzeled..

When I execute

from xlwings import Workbook

in my Python consol (Spyder) the programm runs fine. But once I am trying to run only the program without "priming" it, it gives me the following error message

ImportError: cannot import name 'Workbook'

I wonder what to do to get around this?

As a side note, about a year ago someone else was posting that there is a problem importing the xlwings module 'Workbook' using python 3.4. The fix was using

from xlwings.xlwings import Workbook

which unfortunately does not work for me.

Thank you for any help!

Timo
  • 11
  • 4
  • Can you explain what do you mean by "priming"? – Felix Zumstein Oct 05 '15 at 15:57
  • That fix that you mention has long been resolved and is not necessary anymore. – Felix Zumstein Oct 05 '15 at 15:58
  • I just discovered that when I run the program in my home directory it works fine. But if the program is saved elsewhere it would give me the error. With "priming" I mean importing Workbook in my Spyder Console (which is done in my home directory...) – Timo Oct 05 '15 at 16:18
  • Are you talking about calling the program from VBA, i.e. using the `RunPython` function? – Felix Zumstein Oct 05 '15 at 18:36
  • No, I am just trying to import xlwings while running my code in Spyder, which does not work when the code is saved outside my home directory. Thanks for helping me out! – Timo Oct 06 '15 at 08:30
  • Well, any code you import needs to be on Python's search path, this doens't seem to be an issue specific to xlwings or Spyder: http://stackoverflow.com/questions/3144089/expand-python-search-path-to-other-source – Felix Zumstein Oct 06 '15 at 08:39
  • I don't think this is the problem. I checked sys.path and it contains the correct path to the xlwings library. Afterall, Pandas for example works fine and uses the same search path.. – Timo Oct 06 '15 at 12:56
  • Sure, but the Python file that contains your code might not be on that path I guess. – Felix Zumstein Oct 06 '15 at 15:08
  • I am confused. This is not the first library I am importing and I am saving my files all over the place. They all run fine. But if I try to import xlwings it would not work. I will do some more testing to figure it out. I agree there must be something I am doing wrong, but I can't see what it is... – Timo Oct 06 '15 at 15:44
  • feel free to drop me an email (address is on github). – Felix Zumstein Oct 06 '15 at 16:21

0 Answers0