为什么保存按钮在 matplotlib 绘图上不起作用?
我在 Mac OS X 10.6 上的 Python 2.7 virtualenv 中安装了 matplotlib 1.0.0 。我可以很好地创建情节。但是,每当我按下保存按钮时,我都无法在保存对话框窗口中输入文本,也无法保存绘图。我唯一能做的就是点击取消。对于造成这种情况的原因以及如何解决它有什么想法吗?
Matplotlib 安装过程
我通过克隆安装了 matplotlib astraw 的 matplotlib github 存储库,然后大致遵循 HyperJeff 的安装说明对于 numpy/scipy/matplotlib。以下是 setup.cfg
和 make.osx
的潜在相关部分,包括我在编译和安装之前修改的部分。
setup.cfg
[egg_info]
tag_svn_revision = 1
[directories]
basedirlist = /Users/matthew/.virtualenvs/matplotlib-test
[status]
#suppress = True
#verbose = True
[provide_packages]
[gui_support]
#gtk = False
#gtkagg = False
#tkagg = False
wxagg = False
#macosx = False
[rc_options]
backend = MacOSX
#numerix = numpy
make.osx
# build mpl into a local install dir with
PREFIX=/Users/matthew/.virtualenvs/matplotlib-test
MPLVERSION=1.0rc1
PYVERSION=2.7
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.2.39
FREETYPEVERSION=2.3.11
MACOSX_DEPLOYMENT_TARGET=10.6
OSX_SDK_VER=10.6
ARCH_FLAGS="-arch i386-arch x86_64"
## You shouldn't need to configure past this point (but I did...)
PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="${ARCH_FLAGS} -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="${ARCH_FLAGS} -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-arch i386 -arch x86_64 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="-arch i386 -arch x86_64 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
FFLAGS="-arch i386 -arch x86_64"
修改 setup.cfg
和 make.osx
后,我发出以下命令来安装 matplotlib:
make -f make.osx fetch deps mpl_build mpl_install
python setup.py install
注意: sudo
不是必需的,因为我要安装到 virtualenv 中,而不是像 HyperJeff 那样安装到站点包中。
Python 安装
我使用 python.org 的适用于 Mac OS X 10.5 的 Python 2.7 PPC/i386/x86-64 Mac OS X 安装程序磁盘映像安装了 Python 2.7。感谢 Ned Deily对此问题的回答,我知道这个版本的Python 2.7无法在Mac OS X 10.6上运行IDLE或Tkinter。
问题
- 我安装的 Python 2.7 版本是否是导致问题的原因?我是否应该使用适用于 Mac OS X 10.3 至 10.6 的 Python 2.7 32 位 Mac OS X 安装程序磁盘映像重新安装 Python 2.7?
- 是否需要在 setup.cfg 中配置不同的 gui_support 选项,然后重新编译 matplotlib?
更新,2010 年 9 月 13 日下午 3:33
看来其他 Mac OS X 和 matplotlib 用户也遇到了同样的问题。在 matplotlib-users 邮件列表中, 两名用户报告在 Mac OS X 10.5 上遇到了同样的问题。不过,他们运行的是 matplotlib 0.99.1.1 和 0.99.1.2,而我安装的是 matplotlib 1.0.0。
更新时间:2010 年 9 月 14 日上午 8:18
matplotlib bug 2973874 于 2010 年 3 月 20 日打开,存在同样的问题。然而,它的优先级为 5,并且自从 bug 最初被打开以来就没有被修改过。以下是该错误的描述:
我正在运行6.0.1 enthought python distibution 64位Mac。如果运行绘图并单击保存,我会打开一个保存对话框窗口,我无法在文件名字段中输入文本。我可以选择现有文件,但仍然无法修改名称。如果我选择非 png 文件,它不会覆盖它。我得到一个同名但扩展名为 png 的文件。
I have matplotlib 1.0.0 installed in a Python 2.7 virtualenv on Mac OS X 10.6. I can create plots fine. However, whenever I press the Save button, I can't type text into the save dialog window nor can I save the plot. The only thing I can do is hit cancel. Any thoughts on what's causing this and how to fix it?
Matplotlib installation procedure
I installed matplotlib by cloning astraw's matplotlib github repository and then loosely following HyperJeff's Installation Instructions for numpy/scipy/matplotlib. Below are the potentially relevant sections of setup.cfg
and make.osx
, including the sections that I modified prior to compiling and installing.
setup.cfg
[egg_info]
tag_svn_revision = 1
[directories]
basedirlist = /Users/matthew/.virtualenvs/matplotlib-test
[status]
#suppress = True
#verbose = True
[provide_packages]
[gui_support]
#gtk = False
#gtkagg = False
#tkagg = False
wxagg = False
#macosx = False
[rc_options]
backend = MacOSX
#numerix = numpy
make.osx
# build mpl into a local install dir with
PREFIX=/Users/matthew/.virtualenvs/matplotlib-test
MPLVERSION=1.0rc1
PYVERSION=2.7
PYTHON=python${PYVERSION}
ZLIBVERSION=1.2.3
PNGVERSION=1.2.39
FREETYPEVERSION=2.3.11
MACOSX_DEPLOYMENT_TARGET=10.6
OSX_SDK_VER=10.6
ARCH_FLAGS="-arch i386-arch x86_64"
## You shouldn't need to configure past this point (but I did...)
PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="${ARCH_FLAGS} -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="${ARCH_FLAGS} -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
CFLAGS="-arch i386 -arch x86_64 -I${PREFIX}/include -I${PREFIX}/include/freetype2 -isysroot /Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
LDFLAGS="-arch i386 -arch x86_64 -L${PREFIX}/lib -syslibroot,/Developer/SDKs/MacOSX${OSX_SDK_VER}.sdk"
FFLAGS="-arch i386 -arch x86_64"
After modifying setup.cfg
and make.osx
, I issued the following commands to install matplotlib:
make -f make.osx fetch deps mpl_build mpl_install
python setup.py install
Note: sudo
isn't required, since I'm installing into a virtualenv instead of into the site-packages like HyperJeff is doing.
Python Installation
I installed Python 2.7 using python.org's Python 2.7 PPC/i386/x86-64 Mac OS X Installer Disk Image for Mac OS X 10.5. Thanks to Ned Deily's answer to this SO question, I know that this version of Python 2.7 cannot run IDLE or Tkinter on Mac OS X 10.6.
Questions
- Could the version of Python 2.7 that I have installed be the cause of the problem? Should I reinstall Python 2.7 using the Python 2.7 32-bit Mac OS X Installer Disk Image for Mac OS X 10.3 through 10.6?
- Is there a different
gui_support
option that I need to configure insetup.cfg
and then recompile matplotlib?
Update, September 13, 2010, 3:33 PM
It appears that other Mac OS X and matplotlib users are having the same problem. In the matplotlib-users mailing list, two users reported having the same problem on Mac OS X 10.5. Although, they were running matplotlib 0.99.1.1 and 0.99.1.2 versus matplotlib 1.0.0 that I have installed.
Updated, September 14, 2010, 8:18 AM
matplotlib bug 2973874 was opened on 20-Mar-10 with the same issue. However, it's a priority 5 and hasn't been modified since the bug was originally opened. Below is the description from the bug:
I am running the 6.0.1 enthought python distibution 64bit Mac. If a run a plot and click save I get a save dialog window that opens, I canot enter text in the file name field. I can select an existing file but still cannot modify the name. If I select a non png file it does not overwrite it. I get a file with the same name but with the png extension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要让 OSX 相信 virtualenv 实际上是从应用程序包运行的。此处讨论的修复:
http://groups.google.com/group /python-virtualenv/browse_thread/thread/83fa4a12d22a30c8/744e19c194f1618a
并在这里实现:
https:/ /github.com/gldnspud/virtualenv-pythonw-osx
You need to convince OSX that the virtualenv is actually running from an Application Bundle. Fix discussed here:
http://groups.google.com/group/python-virtualenv/browse_thread/thread/83fa4a12d22a30c8/744e19c194f1618a
And implemented here:
https://github.com/gldnspud/virtualenv-pythonw-osx
我的回答不能解决问题,但可以轻松解决它!您可以在终端中触摸具有正确文件扩展名的新文件。您可以在 matplotlib 窗口中用鼠标选择该文件并覆盖它。
My answer doesn't fix the problem but can workaround it easily! You can touch a new file with the correct file extension in a terminal. After you can choose this file with the mouse inside the matplotlib window and overwrite it.
要解决此问题:
使用
conda install python.app
安装pythonw
。然后在终端中使用
pythonw
而不是python
。例如
希望这有帮助
To solve this:
Use
conda install python.app
to installpythonw
.Then use
pythonw
instead ofpython
in your terminal.E.g.
Hope this helps
对于那些 Thouis 方法不起作用的人:
我注意到一个简单的解决方法是更改 matplotlib 后端。以下是可用后端的列表:
http://matplotlib.org/faq /usage_faq.html#what-is-a-backend
请注意,您应该选择渲染器之一(即支持
show()
命令的渲染器)。您可能需要安装后端,但您可能安装了多个后端。为此:
警告:这应该在导入 pylab 等之前完成。
For those that Thouis method didn't work:
I noticed that a simple work around is to change matplotlib backend. Here is a list of available backends:
http://matplotlib.org/faq/usage_faq.html#what-is-a-backend
Note that you should choose one of the renderer ones (i.e. the ones that support
show()
command). You might need to install the backend, but you might have multiple ones installed.To do so:
Warning: This should be done BEFORE importing pylab, etc.