3

I'm using WingIDE for development and Ipython for running my scripts. I'm facing some inconvenience on several points:

  • Whenever I update my code, I have to reload my module in order to update it in IPython. To solve that I followed Jomonsugi's answer in the following link: How to automatically reload modules in IPython? and it works.

  • Each time I launch IPython, my path is set to my exe's location and I have to cd to my script's directory. I tried to change directory automatically when launching IPython by setting the parameter c.InteractiveShell.ipython_dir = <mypath> in ipython_config.py but it doesn't work.

Is it possible to set the default path? Is there a particular parameter to set in ipython_config.py?

Shreyash S Sarnayak
  • 2,309
  • 19
  • 23
A.Joly
  • 2,317
  • 2
  • 20
  • 25

2 Answers2

3

One way is to use your startup.py file. It should be located somewhere like:

C:/Users/yourname/.ipython/profile_default

If it's not there already, create it. Then use

import os
os.chdir('C:/Users/mypath')

Those two lines will then be run at IPython startup.

Source: IPython.org > Startup Files

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
3

I’m sure Brad Solomon’s answer is right for his version of IPython, but I’ve just downloaded IPython with pip install ipython and my startup files are in a directory nested one deeper than his. My IPython version is 7.18.1, and the start-up files are located in ~/.ipython/profile_default/startup/. There is a README there which states

This is the IPython startup directory

.py and .ipy files in this directory will be run *prior* to any code
or files specified via the exec_lines or exec_files configurables
whenever you load this profile.

Files will be run in lexicographical order, so you can control the
execution order of files with a prefix, e.g.::

        00-first.py
        50-middle.py
        99-last.ipy

That’s pretty self-descriptive, but I would add to this (for anyone coming here from here) that %load_ext autoreload is an IPython command, so you might want to create a file startup.ipy with contents something like this:

%load_ext autoreload
%autoreload 2
print('IPython startup file - created 2020/9/28')