如何更改 IPython 的启动目录 (get_ipython().profile_dir.startup_dir)?

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

我有多个用户的 jupyter/conda 设置。我以前与单个用户一起工作,并在 ~.ipython/profile_default/startup 文件夹中定义了一些 .py 文件。但是那个启动文件夹是 profile/user 独有的。有没有办法让我执行启动文件夹中的文件,而不管启动新笔记本时正在使用哪个user/profile?

简单来说,是否可以在 Jupyter 级别而不是个人用户级别创建 profile_default

谢谢!

一个可能的解决方案是为所有用户设置 IPYTHONDIR 环境变量以指向一个位置,例如:

export IPYTHONDIR=/path/to/.ipython

然后将文件放在/path/to/.ipython/profile_default/startup

定义:

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.

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

然而,有一个很大的陷阱;该目录必须对每个使用它的用户都是可写的。对于每个用户 ~/.ipython 这通常不是问题,但是如果使用诸如 /usr/local/etc.

之类的地方,您应该注意这一要求

另一种解决方案是使用 systemwide configuration 路径,即

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