Nikhil Patil
Nikhil Patil

Reputation: 203

How to change the startup directory (get_ipython().profile_dir.startup_dir) for IPython?

I have a jupyter/conda setup with multiple users. I was previously working with a single user and defined some .py files in the ~.ipython/profile_default/startup folder. But that startup folder is unique to the profile/user. Is there a way for me to execute the files in the startup folder regardless of which user/profile is being used whenever a new Notebook is launched?

In simpler terms, is it possible to create a profile_default at Jupyter level instead of individual user level?

Thank you!

Upvotes: 2

Views: 910

Answers (1)

Brad Solomon
Brad Solomon

Reputation: 40878

One possible solution would be to set the IPYTHONDIR environment variable for all users to point to a single location, such as:

export IPYTHONDIR=/path/to/.ipython

And then place files under /path/to/.ipython/profile_default/startup

Definition:

IPYTHONDIR: If set, this environment variable should be the path to a directory, which IPython will use for user data. IPython will create it if it does not exist.

Source: https://ipython.org/ipython-doc/3/config/intro.html#the-ipython-directory

There is a big gotcha, however; this directory must be writeable by each user that uses it. This is usually not an issue for ~/.ipython for each user, but you should be mindful of this requirement if using a place such as /usr/local or /etc.


Another solution would be to use the systemwide configuration paths, namely

/etc/ipython/
/usr/local/etc/ipython/

Upvotes: 1

Related Questions