Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default IPython profile with environment variable #11862

Open
lewisacidic opened this issue Aug 21, 2019 · 4 comments
Open

Set default IPython profile with environment variable #11862

lewisacidic opened this issue Aug 21, 2019 · 4 comments
Milestone

Comments

@lewisacidic
Copy link

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.

@Carreau Carreau added this to the wishlist milestone Aug 21, 2019
@farisachugthai
Copy link
Contributor

@lewisacidic
Copy link
Author

$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
Copy link

voronind commented 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
Copy link

sfalmo commented 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 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants