You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Set default IPython profile with environment variable #11862
It would be nice to set the IPython profile with an environment variable, i.e. something like
$ IPYTHON_PROFILE=testing ipython
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.7.0 -- An enhanced Interactive Python. Type '?' for help.
IPython profile: testing
In [1]:
My particular use case is to use the conda {de,}activate.d/ hooks to change profiles based on which conda environment is active. At the moment, an easy hack is to alias ipython to ipython --profile={profile} and then unalias in deactivate, but environment variables would be cleaner.
Reacted by Dmitry Voronin, VersBersh, Torbjoern Vik, George G and Ilya Kulakov
Sorry to bump this issue, but for anyone who has a similar problem, I think there is a clean solution without an additional environment variable.
IPython automatically loads the default profile in the $IPYTHONDIR path if it exists. So for a certain environment env, one could create a directory, e.g. $HOME/.ipython/env , and initialize the default profile in there via ipython profile create default --ipython-dir $HOME/.ipython/env. There should now be $HOME/.ipython/env/profile_default, where you can customize your IPython settings.
On activation of the environment, you just have to set the environment variable $IPYTHONDIR to $HOME/.ipython/env (this can be automated in conda) and every IPython process started from now on will automatically select the default profile therein.
Would be handy for per-venv profiles. Storing IPYTHONDIR inside venv is an inconvenience as the whole directory has to be nuked whenever python is updated.
The way I'm doing it now, to preserve the ipython profile between re-creations of venvs:
Activity
farisachugthai commentedon Aug 22, 2019
Have you tried setting $IPYTHONDIR?
https://ipython.readthedocs.io/en/stable/config/intro.html?highlight=ipythondir#envvar-IPYTHONDIR
lewisacidic commentedon Aug 23, 2019
$IPYTHONDIR allows you to redefine
$HOME/.ipython(where the profiles are located) to somewhere else, rather than which profile is selected.You could have a hack where each profile sits in its own .ipython directory, but this is worse than the alias trick.
voronind commentedon Feb 5, 2020
👍
It would be nice to have this feature. Many applications let use IPython instead of standard shell, but we cannot specify profile when it invokes.
sfalmo commentedon Jan 26, 2023
Sorry to bump this issue, but for anyone who has a similar problem, I think there is a clean solution without an additional environment variable.
IPython automatically loads the
defaultprofile in the$IPYTHONDIRpath if it exists. So for a certain environmentenv, one could create a directory, e.g.$HOME/.ipython/env, and initialize the default profile in there viaipython profile create default --ipython-dir $HOME/.ipython/env. There should now be$HOME/.ipython/env/profile_default, where you can customize your IPython settings.On activation of the environment, you just have to set the environment variable
$IPYTHONDIRto$HOME/.ipython/env(this can be automated in conda) and every IPython process started from now on will automatically select the default profile therein.Kentzo commentedon Jun 29, 2024
Would be handy for per-venv profiles. Storing
IPYTHONDIRinside venv is an inconvenience as the whole directory has to be nuked whenever python is updated.The way I'm doing it now, to preserve the ipython profile between re-creations of venvs:
With
IPYTHON_PROFILEthat could be simplified to: