17

I am trying to load things like from __future__ import division on the IPython startup on windows 7 64 bit machine, python 2.7 64 bit.

I searched the web and the recommended way I found is to put a .py file with instructions in: C:\Users\Me\.ipython\profile_default\startup. I've put a simple .py file containing

from __future__ import division
from __future__ import unicode_literals

in that folder. But it actually does nothing. What is more confusing is that the file seems to execute, because if I put some random error line in there, i see an error on Ipython start. Still division is not imported and have to re-import it typing from __future__ import division in the shell.

I tried it both on Anaconda and Winpython(settings for IPython on this distribution are in other folder) with the same result. After I re-import everything works fine. Totally stuck here, please help!

MattDMo
  • 100,794
  • 21
  • 241
  • 231
flipper
  • 531
  • 4
  • 13
  • The solution which is posted here [link](http://stackoverflow.com/questions/20835977/auto-loading-a-module-from-future-on-ipython-startup?rq=1) produces and error. – flipper Jan 02 '14 at 09:10

1 Answers1

25

Check to see if C:\Users\Me\.ipython\profile_default\ipython_config.py exists. If it doesn't, run

ipython profile create

from the command line to generate it. Next, open it in your favorite text editor and search for c.InteractiveShellApp.exec_lines. Uncomment that line (it's line 27 in my file) and edit it to be the following:

c.InteractiveShellApp.exec_lines = ["from __future__ import division", "from __future__ import unicode_literals"]

Save the file, restart IPython, and you should be all set.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • Now I just need django's shell_plus to respect this, and we're all set! – TankorSmash Apr 16 '14 at 15:11
  • note: `get_ipython()` returns `None` in `ipython_config.py`. Create `*.py` files in the `startup` dir if you need access to `ipython` itself (e.g., [to define formatters](https://ipython.readthedocs.io/en/stable/config/integrating.html#formatters-for-third-party-types)) – jfs Nov 05 '18 at 12:13