1
votes

I am trying to use pyplot() backend to plot in Julia with plots(). This is the error I am getting. I am confused about what I need to do to fix this. Can anyone help?

*LoadError: InitError: PyCall.PyError("PyImport_ImportModule\n\nThe Python package matplotlib.pyplot could not be found by pyimport. Usually this means\nthat you did not install matplotlib.pyplot in the Python version being used by PyCall.\n\nPyCall is currently configured to use the Julia-specific Python distribution\ninstalled by the Conda.jl package. To install the matplotlib.pyplot module, you can\nuse pyimport_conda(\"matplotlib.pyplot\", PKG), where PKG is the Anaconda\npackage the contains the module matplotlib.pyplot, or alternatively you can use the\nConda package directly (via using Conda followed by Conda.add etcetera).\n\nAlternatively, if you want to use a different Python distribution on your\nsystem, such as a system-wide Python (as opposed to the Julia-specific Python),\nyou can re-configure PyCall with that Python. As explained in the PyCall\ndocumentation, set ENV[\"PYTHON\"] to the path/name of the python executable\nyou want to use, run Pkg.build(\"PyCall\"), and re-launch Julia.\n\n", PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x0000000166bd5f40), PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x00000001a99e3748), PyCall.PyObject(Ptr{PyCall.PyObject_struct} @0x00000001a99f75c8)) during initialization of module PyPlot *

1

1 Answers

2
votes

This is definitely "many Pythons" issue. Basically in Julia you have always two options:

  1. use the Julia in-built Anaconda Python
  2. use an external (Anaconda) Python installation

I prefer the second option since most of a data science/scientific computing machines have an Anaconda anyway and I like more having one Anaconda to manage than many Anacondas.

Ad 1. The inbuilt Python is used when no PYTHON environment variable is set (in the Julia console look for the value of ENV["PYTHON"]) Basically the first thing usually to try is to press ] for the package manager and run:

(v1.0) pkg> build PyCall

(v1.0) pkg> build PyPlot

Ad 2. Set the PYTHON environment variable (I use sample, typical paths)

Windows (or go to computer management and set the system variables):

$ set PYTHON=C:\ProgramData\Anaconda3\python.exe

Linux (sample Ubuntu configuration):

$ export PYTHON=/home/ubuntu/anaconda3/bin/python

Julia console (on Linux Ubuntu)

julia> ENV["PYTHON"]="/home/ubuntu/anaconda3/bin/python"

Once done go to the Julia package manager and rebuild packages:

(v1.0) pkg> build PyCall

(v1.0) pkg> build PyPlot

Should work.