【问题标题】:Best way for conda environment to use individual ipython and matplotlib config filesconda 环境使用单个 ipython 和 matplotlib 配置文件的最佳方式
【发布时间】:2020-09-29 05:49:56
【问题描述】:

我刚刚在 mac 上安装了 miniconda 以使用 python 3。但是我安装了 python 2,我想保留的老式方式。 ipython 和 matplotlib 的旧配置文件位于我的主目录的默认位置(~/.ipython/profile_default/ 和 ~/.matplotlib/matplotlibrc)。

我想我会使用 conda 环境来隔离我的新 python3,所以我创建了一个新的“主”环境

conda create --name=main

并在我的新环境中安装了 ipython 和 matplotlib

conda activate main
conda install ipython matplotlib

什么是我的新 ipython 和 matplotlib 使用自己的配置文件的好方法?我想保留旧的配置文件,以便在需要时仍然可以使用旧的 python 2。

我的一点点进步是在我的新main conda 环境中我运行了ipython profile create condaenv_main,它在 ~/.ipython/profile_condaenv_main 中创建了一个新的 ipython 配置文件。如果我在这个环境中(可能有一些别名或其他东西),有没有办法让 ipython 自动加载这个配置文件? IE。我希望能够输入

conda activate main
ipython

而不是

conda activate main
ipython --profile=condaenv_main

现在第一种方法会加载我不想要的旧 profile_default ipython。

有没有一种类似的方法可以让 conda main 环境的 matplotlib 配置也仅针对 main 分开?

【问题讨论】:

    标签: python matplotlib ipython conda miniconda


    【解决方案1】:

    这里有一个解决方案:

    对于 ipython,我遵循here 的想法来定义别名 alias ipython="ipython --profile=condaenv_main" 当环境被激活时,unalias ipython 当被停用时。指令是here

    对于 matplotlib,我创建了一个名为 condaenv_main/ 的 ~/.matplotlib 子目录,并将我的新 matplotlibrc 文件放在那里。然后我在激活环境时 conda 设置了环境变量MPLCONFIGDIR(当环境被停用时它会自动删除)。命令是(见here):

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

    【讨论】:

      猜你喜欢
      • 2014-10-16
      • 2017-11-24
      • 1970-01-01
      • 2018-06-21
      • 2014-08-31
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      相关资源
      最近更新 更多