Skip to content
This repository

profile/startup files not executed with "notebook" #1191

Closed
hayne opened this Issue December 20, 2011 · 3 comments

2 participants

Cameron Hayne Min RK
Cameron Hayne

The new HTML notebook feature in iPython 0.12 doesn't seem to be executing the Python files that are in the "startup" sub-folder of the profile folder I specify.
I'm starting iPython with the following command line (this is on Windows XP by the way):

ipython notebook --ipython-dir iPythonDir

where "iPythonDir is a sub-directory of the current directory which has a "profile_default" sub-directory and a "profile_default/startup" sub-sub-directory.
In the later directory I have a file named "iPythonStartup.ipy" which does a few things, ending with a print statement telling me that it is finished.

If I run ipython without the "notebook" sub-command like this:

ipython --ipython-dir iPythonDir

then my ".ipy" file from the "startup" folder is run as expected.
I know that it is getting executed not only because I see the "Finished ..." output from my print statement,
but (more importantly) because when I evaluate something like: 2 / 3
I get 0.6666 instead of the 0 I would have gotten if it hadn't run the line in my ".ipy" file that does "from future import division".
(I'm using Python 2.7 so division of two integers is truncated integer division by default.)

Here's what I see in the terminal window in that case: (note the "Finished ..." line that was printed from my ".ipy" file)

------
ipython --ipython-dir iPythonDir
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit  
(Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
Finished executing code from 'ipythonStartup.ipy'
In [1]: exit
------

But when I use the "notebook" sub-command, I see: (Note that there is no "Finished ..." line in the output)

------
ipython notebook --ipython-dir iPythonDir
[NotebookApp] Using existing profile dir: u'iPythonDir\\profile_default'
[NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888
[NotebookApp] Use Control-C to stop this server and shut down all  
kernels.
^C
------

Note that I know that my ".ipy" file isn't getting executed because

when I evaluate something like: 2 / 3
in the notebook, I get 0
(So I know that the line from __future__ import division from my

".ipy" file wasn't executed.)

As a side note, it isn't entirely clear where the output (stdout) from startup files should be going - should it appear in the terminal window where iPython was started, or should it appear in the notebook(s)?
(But not to be distracted by this question - the bug is that the startup files don't seem to get executed at all. Or is it perhaps that the "profile_default" folder is not used when in "notebook" mode?)

Min RK
Owner

The profile is definitely used in the notebook, as are the startup files. I can confirm that this does work for me (including from __future__ import division, and specifying the ipython-dir on the command-line.

Note that you will not see any printed messages from startup scripts in the notebook, because stdout/err that is not associated with notebook execution is not displayed.

Can you post the whole script, and possibly check the javascript console log for any illuminating messages (stdout from your script should be caught under 'IOPub message not from one of my cells' if it ran).

Cameron Hayne

Hmm. Now it seems to be working. I'm not sure what I was doing wrong before. This is especially mysterious since I think I ran those two tries I showed in my original report (with and without "notebook") one after the other without changing anything in my configuration.
But one theory I have is that maybe I had accidentally changed directory so that the folder specified via "--ipython-dir" did not exist in the current directory. (I was specifying the ipython-dir via a relative path.) If this had happened, iPython would have helpfully created a new folder with the name I specified and this new folder would of course not have any startup files. I don't think that happened, but I can't see any other explanation for why it wasn't working then and is now.

But as I said, it now seems to be working.
I get .666 in the notebook when I evaluate 2 / 3
so the "from future import division" in my ".ipy" file is taking effect.

The strange thing is (given what "minrk" said above) that I also am now seeing the "Finished ..." output from the print statement in my startup ".ipy" file. This output appears in the notebook cell when I first execute some code in that cell. I.e. the output from the print statement doesn't appear earlier, even though it was issued earlier (as I can see by printing a timestamp).

Min RK
Owner

Ah, thanks for the note - the print statement will come out associated with the first cell because the stdout.flush() that draws the line between preflight code and the first cell is happening too early. The tiny fix necessary is included in PR #1187.

Min RK minrk closed this December 21, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.