繁体   English   中英

Julia PyPlot无法正常工作[Conda,Python问题]

[英]Julia PyPlot not working [Conda, Python issues]

这是我运行程序时遇到的错误。 我正在使用Ubuntu 16.04,并安装了Python 2.7.12。 我安装了anaconda,希望可以帮助解决问题,但没有成功。 现在python -V给了我Python 2.7.14 :: Anaconda, Inc.

当我在julia中运行Conda.list() ,我确实得到了“ matplotlib”和“底图”(我认为包括mpl_toolkits),而当我在julia之外运行conda list (bash?),我得到了一个更长的列表,其中也包含“ matplotlib ”和“底图”。

   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

做到了!

谢谢Github!

我也在使用Ubuntu 16.04,并在茱莉亚中使用pyplot。 我使用pip安装了matplotlib,并将其与TK后端(最轻巧且易于安装的后端)一起使用。 请尝试以下Shell命令在主目录中安装python-tk和matplotlib:

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")'

要使用默认的python解释器,请确保未设置环境变量PYTHON 以下应该不返回nothing

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

如果尚未安装PyCallPyPlot ,则使用add代替build

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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