Setting the default conda environment for Julia

Viewed 2625

I'm just starting to learn Julia in a windows platform. I've been using for quiet some time python (through miniconda and a virtual environment that I will call from now on p3). Also, I like using VSCode, so I am using the Julia 1.0.0 extension.

One of my first tasks was aimed at creating a simple plot. While I was using the Pkg, to add Plots and PyPlot, I noticed that for the latter the following command was issued: conda install matplotlib.

Because I use Miniconda (that is the base environment), I initially suspected that the (base) environment was called. However upon closer inspection I realised that in my user folder there was a .julia/conda folder that contained the data.

So my questions are:

  • does julia use and maintain a separate conda environment in order to communicate with python?
  • Is it possible to move the .julia folder (or more specifically the conda folder which tends to get a bit bulky to another directory).
  • Is it possible to create different conda environments for use within julia?

If my questions are too naive/answered elsewhere, then I would appreciate it if you could just point me to the relative documentation/tutorial.

2 Answers

As far as I understand, PyPlot.jl relies on PyCall.jl to run python code. In turn PyCall relies on Conda.jl to manage the python environment.

While Conda.jl allows you to manage several environments, it looks like only the "root" environment will be used by PyCall. The Conda.jl documentation gives a few pointers on how to change the location of this root environment.

So, to answer your questions:

does julia use and maintain a separate conda environment in order to communicate with python?

By default, yes

Is it possible to move the .julia folder (or more specifically the conda folder which tends to get a bit bulky to another directory).

It is possible to move the entire .julia folder by setting the JULIA_DEPOT_PATH environment variable. Or to move only the conda root environment by setting the CONDA_JL_HOME env var and rebuilding Conda.jl as explained in the link above.

Is it possible to create different conda environments for use within julia?

Not sure I understand your question. If you mean to ask whether there can be multiple possible conda environments and you'd choose which one to use for a particular Julia session, then AFAIU no: everything relying on PyCall will ever use the "root" conda environment.

By default Julia is using the inbuilt Anaconda, however you can use any other Python installation. You can change the Python environment that is used with Julia by pointing to a different Python executeable:

ENV["PYTHON"]="C:\\ProgramData\\Anaconda3\\python.exe"
using Pkg
pkg"build PyCall"

Note that after changing the environment PyCall needs to be rebuilt. You can manage your packages either via Conda.jl or conda command that comes with Python installation or even pip. Julia should work with any Python installation, however with the Anaconda or Miniconda distribution you will have the best experience.

I recommend also reading PyCall installation instructions

Finally, if you are not happy with your new Python configuration the above can be reverted to the inbuilt Python via:

ENV["PYTHON"]=""
pkg"build PyCall"
Related