How to use ANACONDA's Python from Julia

Hi,
I am using Pycall to call Python from Julia. From Julia Prompt I used Pkg.add(“PyCall”). During its installation its downloading miniconda for Python.
I have anaconda in my PC and want to use Anaconda’s Python. Is their any way?

From the package README file:

If you want to use a different version of Python than the default [miniconda], you can change the Python version by setting the PYTHON environment variable to the path of the python executable and then re-running Pkg.build(“PyCall”). In Julia:

ENV[“PYTHON”] = "… path of the python program you want …"
Pkg.build(“PyCall”)

2 Likes

Is Anaconda’s Python on the path? If so, it should not download a new Python installation.

As pointed out by @dpsanders in the post below, this is the default only for Linux. Julia on Windows and Mac downloads a minimal private Python installation.

That changes as of IJulia 1.4 (if I remember correctly). The default is now always to download a new conda installation, to try to ensure the correct versions of everything.

How can you do it on Windows?

The same thing should work, or run set PYTHON=c:\path\to\python in a prompt before starting julia.

2 Likes

ive not had any luck with this on windows:

ive tried:

julia> ENV[“PYTHON”] = “C:\Users\jason\Anaconda3\python.exe”
ERROR: syntax: invalid escape sequence

and

julia> ENV[“PYTHON”] = “C:\Users\jason\Anaconda3”
ERROR: syntax: invalid escape sequence

is it because python.exe is version 3.7.0?

You can either do it as ihnorton suggested or you can do it the way you tried. When doing the latter, you should escape the backslash. i.e.,
ENV["PYTHON"] = "C:\\Users\\jason\\Anaconda3"
I am not sure whether you should add \\python.exe though.

Yes, PYTHON should be the path of the Python executable (including the executable name). Note that you can also use raw"C:\Users\jason\Anaconda3\python.exe" to avoid escaping the backslashes.