Best way for conda environment to use individual ipython and matplotlib config files

Viewed 425

I just installed miniconda on mac in order to use python 3. But I have python 2 installed the old fashioned way that I want to preserve. The old configuration files for ipython and matplotlib are in my home directory at the default locations (~/.ipython/profile_default/ and ~/.matplotlib/matplotlibrc).

I thought I would use the conda environments to isolate my new python3 so I made a new "main" environment with

conda create --name=main

and installed ipython and matplotlib in my new environment

conda activate main
conda install ipython matplotlib

What is a good way for my new ipython and matplotlib to use their own configuration files? I want to keep the old config files in place so I can still use my old python 2 if I need to.

My tiny bit of progress was that in my new main conda environment I ran ipython profile create condaenv_main, which created a new ipython profile in ~/.ipython/profile_condaenv_main. Is there a way that I can have ipython load this profile automatically if I'm in this environment (maybe with some aliases or something)? I.e. I would like to be able to type

conda activate main
ipython

rather than

conda activate main
ipython --profile=condaenv_main

Right now the first way would load my old profile_default ipython which I don't want.

Is there an analogous way I can keep the conda main environment's matplotlib config also separate just for main?

1 Answers

Here's one solution:

For ipython I followed the idea here to define the alias alias ipython="ipython --profile=condaenv_main" when the environment is activated and unalias ipython when deactivated. The instructions are here.

For matplotlib I created a subdirectory of ~/.matplotlib called condaenv_main/ and put my new matplotlibrc file in there. Then I have conda set the environment variable MPLCONFIGDIR when environment is activated (and it is automatically removed when environment is deactivated). The command is (see here):

conda env config vars set MPLCONFIGDIR=$HOME/.matplotlib/condaenv_main

Related