Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ExcelPython with iPython #37

Open
dvincentwest opened this issue Nov 21, 2014 · 1 comment
Open

Using ExcelPython with iPython #37

dvincentwest opened this issue Nov 21, 2014 · 1 comment

Comments

@dvincentwest
Copy link

A few users have mentioned the desire to have modules auto-reload, which certainly would be nice when developing calculations and other things to go along with that. It occurred to me that we should just be able to use ipython, instead of pythonw, and have things interface that way, and then use a special excel-python profile to activate the autoreload module for ipython.

first I created an ipython profile by running,
ipython profile create excelpython

Then in the ipython_profile.cfg file in the newly created profile_excelpython folder, I put the two lines:

c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']

using this profile in a command line works as expected, auto-reloading modules on the fly.

Then I went into the excelpython config file and I changed line 25 of the xlpython.cfg file from:
Command = pythonw.exe -u "$(ConfigDir)\xlpyserver.py" $(CLSID)
to
Command = ipython.exe --profile=excelpython "$(ConfigDir)\xlpyserver.py" $(CLSID)

It launches correctly, and will do python calculations as expected (at least in simple cases), although now it pops up a persistent window for the python runtime.

However, the auto-reload feature is not working as expected, and modules are not re-loading as they do when working in one of the standard ipython interfaces.

Is there an intrinsic reason this won't work, or maybe this is just a setting or a small change somewhere?

@ericremoreynolds
Copy link
Owner

Hello,

Assuming you are the person who made a donation recently, thanks very much for supporting the development of ExcelPython!

We are currently looking into ways to use IPython together with ExcelPython, indeed it is part of our project to integrate with xlwings. ExcelPython was indeed designed with this future use case in mind, so it's really a question of understanding how the two interact together.

The fact that a window is popping up is to be expected, it is the reason in fact why in the default config file pythonw.exe is used instead of python.exe.

It is possible that autoreload is not working because once the control passes over to the xlpyserver.py script, Python enters into a Windows message loop to service the COM server, and therefore IPython/autoreload no longer gets a chance to do its magic. In other words what is probably necessary is to launch the COM server in a seperate thread leaving IPython free for user interaction and extension processing.

However to really understand what is going on I'd need to get into the details of how the autoreload extension works - which I will definitely put on my todo list, which unfortunately is already rather full and expanding at an abominable rate 😄.

It may on the other hand be related to the fact that ExcelPython does not load the WorkbookName.py script as a module, but using its own mechanism which kinda does what autoreload does. Perhaps this code (in xlpython\__init__.py) could be modified to implicitly use autoreload instead? This could be the cause of the problem.

As soon as I have a sec I will have a look into it, in the mean time if you make any headway please let me know!

Best regards,

Eric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants