我在安装matplotlib软件包后无法将matplotlib.pyplot作为plt导入.任何建议都将非常感激.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "//anaconda/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.5-x86_64.egg/matplotlib/backends/backend_macosx.py", line 21, in <module>
from matplotlib.backends import _macosx
**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 …Run Code Online (Sandbox Code Playgroud) 长话短说:pythonw.exe什么都不做,python.exe什么都不接受(我应该使用哪一个?)
test.py:
print "a"
Run Code Online (Sandbox Code Playgroud)
CMD窗口:
C:\path>pythonw.exe test.py
<BLANK LINE>
C:\path>
C:\path>python.exe test.py
File "C:\path\test.py", line 7
print "a"
^
SyntaxError: invalid syntax
C:\path>
Run Code Online (Sandbox Code Playgroud)
请告诉我,我做错了什么.
我正在虚拟环境中使用flask.我能够用pip安装matplotlib,我可以import matplotlib在Python会话中.但是,当我导入它时
matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "//anaconda/envs/myenv/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
from matplotlib.backends import _macosx
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 …Run Code Online (Sandbox Code Playgroud) 之前已经问过这个问题,在这里,也在这里.但是,解决方案并没有解决我的问题.
最初的错误是,当我尝试时import matplotlib.pyplot,我得到:
回溯(最近一次调用最后一次):文件"",第1行,文件"/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py",第114行,在_backend_mod,new_figure_manager中, draw_if_interactive,_show = pylab_setup()文件"/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/ INIT py"为32行,在pylab_setup全局(),当地人(),[backend_name ],0)文件"/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py",第24行,来自matplotlib.backends import _macosx RuntimeError:Python未安装为框架.如果未将Python安装为框架,则Mac OS X后端将无法正常运行.有关在Mac OS X上安装Python作为框架的更多信息,请参阅Python文档.请重新安装Python作为框架,或尝试其他后端之一.如果您在虚拟环境中使用Matplotlib,请参阅Matplotlib中的"在虚拟环境中使用Matplotlib"常见问题解答
我按照解决方案添加了一个~/.matplotlib/matplotlibrc包含以下代码的文件:backend: TkAgg.这样做之后,我的错误变为:
/Users/XX/anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273:UserWarning:Matplotlib正在使用fc-list构建字体缓存.这可能需要一点时间.warnings.warn('Matplotlib正在使用fc-list构建字体缓存.这可能需要一些时间.')objc [25120]:类TKApplication在/Users/XX/anaconda/lib/libtk8.5.dylib和/ /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk.将使用两者之一.哪一个未定义.objc [25120]:类TKMenu在/Users/XX/anaconda/lib/libtk8.5.dylib和/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk中实现.将使用两者之一.哪一个未定义.objc [25120]:类TKContentView在/Users/XX/anaconda/lib/libtk8.5.dylib和/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk中实现.将使用两者之一.哪一个未定义.objc [25120]:类TKWindow在/Users/XX/anaconda/lib/libtk8.5.dylib和/System/Library/Frameworks/Tk.framework/Versions/8.5/Tk中实现.将使用两者之一.哪一个未定义.
我不知道如何解决这个问题.我没有使用虚拟机.你可以帮帮我吗?谢谢!
PS:我发现通过添加:
import matplotlib
matplotlib.use('TkAgg')
之前import matplotlib.pyplot,它似乎工作.但每次添加这两行代码都很烦人...有谁知道发生了什么以及如何解决它?谢谢!
我用pkg安装程序安装了Anaconda:
Python 2.7.10 |Continuum Analytics, Inc.| (default, May 28 2015, 17:04:42)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用matplotlib中的任何东西时,即:
from matplotlib import pyplot as plt
Run Code Online (Sandbox Code Playgroud)
我明白了
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 …Run Code Online (Sandbox Code Playgroud) matplotlib与 MacOS 一起使用的问题是一个棘手的问题,已经通过许多讨论(见下文)进行了彻底审查。问题如下:
这是我想出的最简单的代码片段,它允许重现问题:
from matplotlib import pyplot as plt
x = [1, 2, 3]
y = [1, 2, 3]
plt.plot(x, y)
plt.show()
Run Code Online (Sandbox Code Playgroud)
这会引发以下错误:
2019-03-22 12:25:43.429 python3.7[22209:554135] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7f85866b9de0
2019-03-22 12:25:43.431 python3.7[22209:554135] \*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7f85866b9de0'
*** First throw call stack:([...])
libc++abi.dylib: terminating with uncaught exception of type …Run Code Online (Sandbox Code Playgroud) 我可以通过终端运行代码并使用图表弹出matplotlib窗口但不通过Pycharm.我得到的只是一个错误说:
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 …Run Code Online (Sandbox Code Playgroud) 上下文
错误消息
以下课程[ Jerry Kurata 'Tensorflow: Getting Started']运行以下内容:
import tensorflow as tf
import numpy as np
import math
import matplotlib.pyplot as plt
import matplotlib.animation as animation
num_house = 160
np.random.seed(42)
house_size = np.random.randint(low=1000, high=3500, size=num_house)
np.random.seed(42)
house_price = house_size * 100.0 + np.random.randint(low=20000, high=70000, size=num_house)
plt.plot(house_size, house_price, "bx")
plt.xlabel("price")
plt.ylabel("size")
plt.show
Run Code Online (Sandbox Code Playgroud)
收到此错误
**RuntimeError**: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not …
python ×8
macos ×7
matplotlib ×7
anaconda ×2
virtualenv ×2
flask ×1
pycharm ×1
python-2.7 ×1
python-3.x ×1
tensorflow ×1