Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法将@pyimport matplotlib.pyplot作为plt导入Julia中的matplotlib_Python_Matplotlib_Import_Julia - Fatal编程技术网

Python 无法将@pyimport matplotlib.pyplot作为plt导入Julia中的matplotlib

Python 无法将@pyimport matplotlib.pyplot作为plt导入Julia中的matplotlib,python,matplotlib,import,julia,Python,Matplotlib,Import,Julia,您好,我试图在Julia中使用matplotlib,并使用命令Pkg.build(“PyCall”)使用PyCall@pyimport matplotlib.pyplot作为plt,但我一直收到以下错误消息: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)) <type 'exceptions.RuntimeError'> RuntimeError("Python is not insta

您好,我试图在Julia中使用matplotlib,并使用命令
Pkg.build(“PyCall”)
使用PyCall
@pyimport matplotlib.pyplot作为plt
,但我一直收到以下错误消息:

PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)) <type 'exceptions.RuntimeError'>
RuntimeError("Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.",)
  File "/Users/mymac/Library/Python/2.7/lib/python/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/mymac/Library/Python/2.7/lib/python/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Users/mymac/Library/Python/2.7/lib/python/site-packages/matplotlib/backends/backend_macosx.py", line 19, in <module>
    from matplotlib.backends import _macosx
PyError(ccall(@pysym(:PyImport\u ImportModule),PyPtr,(Cstring,),name))
运行时错误(“Python未作为框架安装。如果Python未作为框架安装,Mac OS X后端将无法正常运行。有关在Mac OS X上安装Python作为框架的详细信息,请参阅Python文档。请将Python作为框架重新安装,或尝试其他后端之一。如果您使用(Ana)Conda请安装python.app并将“python”替换为“pythonw”。有关详细信息,请参阅Matplotlib常见问题解答中的“在OSX上使用Matplotlib”。)
文件“/Users/mymac/Library/Python/2.7/lib/Python/site packages/matplotlib/pyplot.py”,第115行,在
_后端模块、新图形管理器、绘图(如果交互式),显示=pylab\u设置()
文件“/Users/mymac/Library/Python/2.7/lib/Python/site packages/matplotlib/backends/_init___;.py”,pylab_设置中的第32行
全局变量(),局部变量(),[backend_name],0)
文件“/Users/mymac/Library/Python/2.7/lib/Python/site packages/matplotlib/backends/backend_macosx.py”,第19行,在
从matplotlib.backends导入_macosx
以下是我已经尝试过的步骤

  • 在一个Julia内核中,它试图运行
    @pyimport math
    ==>这是可行的

  • 在Python内核中,我尝试运行
    import matplotlib作为plt
    =>它可以工作

  • 我卸载了MacOS 10.13.2上的所有python版本,并重新安装了python版本3.6.5。我仍然收到相同的错误消息

  • 在终端中,我尝试运行:
    $curl-Ohttps://bootstrap.pypa.io/get-pip.py
    然后
    python3获取pip.py
    但仍会在Julia中获取错误消息

  • /Users/mymac/Library/
    中删除Python后,Julia似乎重新创建了路径
    /Users/mymac/Library/Python/2.7/


非常感谢您

您是否尝试过在Julia中安装PyPlot.jl软件包

Pkg.install("PyPlot")

非常感谢@juliohm!在运行了
Pkg.add(“PyPlot”)
使用PyPlot
之后,我现在可以运行
plot()
如果我正确理解Julia中matplotlib的副本,也就是说,唯一的一个小细节是,当我试图使用命令
@pyimport matplotlib.pyplot as plt
从python导入pyplot时,给出了错误消息
@pyimport:plt已经定义了
。显然已经有一个函数
plt()
在Julia中。或者,我可以以mplt运行
@pyimport matplotlib.pyplot
。再次感谢pyplot.jl包导出您需要的每个matplotlib函数。如果matplotlib中缺少任何函数,请在GitHub上打开一个问题,维护人员将修复它。另一个建议是检查Plots.jl包。它与很多其他的后台,不仅仅是Python中的matplotlib。对于那些对我的问题投了反对票的人,我很高兴知道问题被否决的原因:如果1.问题的风格或准确性不够好,就写出来吧:我非常渴望学习和改进如何写更好的问题。如果是2.因为问题是重复的,只需写下来作为答案:我非常乐意投赞成票并接受它作为答案。如果3.还有另一个原因我没有得到,请也写下来。但我必须说,我觉得“免费”投反对票而没有任何解释的态度令人恼火和无用