简体   繁体   中英

Julia PyPlot not working [Conda, Python issues]

This is the error I get when I run my program. I am using Ubuntu 16.04 and had Python 2.7.12 installed. I installed anaconda hoping that would help solve the problem but it didn't. Now python -V gives me Python 2.7.14 :: Anaconda, Inc.

When I run Conda.list() inside julia, I do get "matplotlib" and "basemap" (includes mpl_toolkits, I think) and when I run conda list outside julia (bash?) I get a longer list which also contains "matplotlib" and "basemap".

   sys:1: UserWarning:  This call to matplotlib.use() has no effect because the backend has already been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.

The backend was *originally* set to u'Qt5Agg' by the following code:   File "/home/myusername/anaconda2/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 14, in <module>
    line for line in traceback.format_stack()


WARNING: No working GUI backend found for matplotlib WARNING: Couldn't initialize pyplot.  (might need to install it?) INFO: To do a standard install of pyplot, copy and run this:

if !Plots.is_installed("PyPlot")
    Pkg.add("PyPlot") end withenv("PYTHON" => "") do
    Pkg.build("PyPlot") end

# now restart julia!


ERROR: LoadError: InitError: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)

The Python package matplotlib.pyplot could not be found by pyimport. Usually this means that you did not install matplotlib.pyplot in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:

/home/myusername/anaconda2/bin/python

and you should use whatever mechanism you usually use (apt-get, pip, conda, etcetera) to install the Python package containing the matplotlib.pyplot module.

One alternative is to re-configure PyCall to use a different Python version on your system: set ENV["PYTHON"] to the path/name of the python executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python distribution via the Conda.jl package (which installs a private Anaconda Python distribution), which has the advantage that packages can be installed and kept up-to-date via Julia.  As explained in the PyCall documentation, set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then, To install the matplotlib.pyplot module, you can use `pyimport_conda("matplotlib.pyplot", PKG)`, where PKG is the Anaconda package the contains the module matplotlib.pyplot, or alternatively you can use the Conda package directly (via `using Conda` followed by `Conda.add` etcetera).

) <type 'exceptions.ImportError'> ImportError("/lib/x86_64-linux-gnu/libz.so.1: version `ZLIB_1.2.9' not found (required by /home/myusername/anaconda2/lib/python2.7/site-packages/matplotlib/../../.././libpng16.so.16)",) File "/home/myusername/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 29, in <module>
    import matplotlib.colorbar   File "/home/myusername/anaconda2/lib/python2.7/site-packages/matplotlib/colorbar.py", line 36, in <module>
    import matplotlib.contour as contour   File "/home/myusername/anaconda2/lib/python2.7/site-packages/matplotlib/contour.py", line 21, in <module>
    import matplotlib.font_manager as font_manager   File "/home/myusername/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py", line 58, in <module>
    from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir

Stacktrace:  [1] pyerr_check at /home/myusername/.julia/v0.6/PyCall/src/exception.jl:56 [inlined]....
LD_LIBRARY_PATH="/home/myusername/.julia/v0.6/Conda/deps/usr/lib/" julia

did it!

Thanks Github!

I am also using Ubuntu 16.04 and use pyplot with julia. I installed matplotlib with pip and use it with the TK backend (the most light-weight and easy to install backend). Please try these shell commands to install python-tk and matplotlib in your home directory:

sudo apt-get install python-tk
unset PYTHON # to use the default python interpreter /usr/bin/python
pip2 install --user --upgrade matplotlib
julia --eval 'Pkg.build("PyCall")'
julia --eval 'Pkg.build("PyPlot")'

To use the default python interpreter, make sure that you do not set the environment variable PYTHON . The following should return nothing :

julia --eval '@show get(ENV,"PYTHON",nothing)'

If PyCall are PyPlot are not already installed, then use add instead of build :

julia --eval 'Pkg.add("PyCall")'
julia --eval 'Pkg.add("PyPlot")'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM