matplotlib.pyplot 和 wx 使用 python 2.7.10 导入问题
matplotlib.pyplot and wx importing problems using python 2.7.10
我为一个项目安装了很多库,但是当我尝试导入 python 时,有两个特定的库给我带来了麻烦。这两个是matplotlib.pyplot和wxpython。我已经按照许多教程了解如何将这些软件包正确安装到 python 中,但到目前为止我还没有运气。这是尝试导入时出现的错误:
Traceback (most recent call last):
File "/Users/AhmedNiri/Ahmed/2D_Mapping_Program_V7.py", line 13, in <module>
import matplotlib.pyplot as plt
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/backends/backend_wxagg.py", line 6, in <module>
import backend_wx # already uses wxversion.ensureMinimal('2.8')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/backends/backend_wx.py", line 53, in <module>
raise ImportError(missingwxversion)
ImportError: Matplotlib backend_wx and backend_wxagg require wxversion, which was not found.
那么我怎么知道这两个库已经正确安装在所需的目录中呢?
我知道这可能是一个容易回答的问题,但我已经尝试了一段时间来解决这个问题,而且我在 python 方面也没有太多经验。提前致谢。
问题已解决,解决方法如下。在我安装 wxpython 并使用 "brew install wxpython> install.log 2>error.log" 捕获输出后,我发现安装 wxpython 时它没有正确的目录,它还告诉您如何更改此目录。捕获的输出如下所示:
==> Installing wxpython dependency: wxmac
==> Downloading https://homebrew.bintray.com/bottles/wxmac-3.0.2.yosemite.bottle.10.tar.gz
Already downloaded: /Library/Caches/Homebrew/wxmac-3.0.2.yosemite.bottle.10.tar.gz
==> Pouring wxmac-3.0.2.yosemite.bottle.10.tar.gz
/usr/local/Cellar/wxmac/3.0.2: 777 files, 41M
==> Installing wxpython
==> Downloading https://homebrew.bintray.com/bottles/wxpython-3.0.2.0.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/wxpython-3.0.2.0.yosemite.bottle.tar.gz
==> Pouring wxpython-3.0.2.0.yosemite.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
/usr/local/Cellar/wxpython/3.0.2.0: 944 files, 38M
因此,如果您查看上面的执行,您可以看到:
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages/homebrew.pth
这是用来解决问题的部分。我希望这可以帮助其他人,我要感谢@JoranBeasley 的帮助。
我为一个项目安装了很多库,但是当我尝试导入 python 时,有两个特定的库给我带来了麻烦。这两个是matplotlib.pyplot和wxpython。我已经按照许多教程了解如何将这些软件包正确安装到 python 中,但到目前为止我还没有运气。这是尝试导入时出现的错误:
Traceback (most recent call last):
File "/Users/AhmedNiri/Ahmed/2D_Mapping_Program_V7.py", line 13, in <module>
import matplotlib.pyplot as plt
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/backends/__init__.py", line 28, in pylab_setup
globals(),locals(),[backend_name],0)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/backends/backend_wxagg.py", line 6, in <module>
import backend_wx # already uses wxversion.ensureMinimal('2.8')
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib-1.3.1-py2.7-macosx-10.9-x86_64.egg/matplotlib/backends/backend_wx.py", line 53, in <module>
raise ImportError(missingwxversion)
ImportError: Matplotlib backend_wx and backend_wxagg require wxversion, which was not found.
那么我怎么知道这两个库已经正确安装在所需的目录中呢? 我知道这可能是一个容易回答的问题,但我已经尝试了一段时间来解决这个问题,而且我在 python 方面也没有太多经验。提前致谢。
问题已解决,解决方法如下。在我安装 wxpython 并使用 "brew install wxpython> install.log 2>error.log" 捕获输出后,我发现安装 wxpython 时它没有正确的目录,它还告诉您如何更改此目录。捕获的输出如下所示:
==> Installing wxpython dependency: wxmac
==> Downloading https://homebrew.bintray.com/bottles/wxmac-3.0.2.yosemite.bottle.10.tar.gz
Already downloaded: /Library/Caches/Homebrew/wxmac-3.0.2.yosemite.bottle.10.tar.gz
==> Pouring wxmac-3.0.2.yosemite.bottle.10.tar.gz
/usr/local/Cellar/wxmac/3.0.2: 777 files, 41M
==> Installing wxpython
==> Downloading https://homebrew.bintray.com/bottles/wxpython-3.0.2.0.yosemite.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/wxpython-3.0.2.0.yosemite.bottle.tar.gz
==> Pouring wxpython-3.0.2.0.yosemite.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages/homebrew.pth
==> Summary
/usr/local/Cellar/wxpython/3.0.2.0: 944 files, 38M
因此,如果您查看上面的执行,您可以看到:
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/AhmedNiri/Library/Python/2.7/lib/python/site-packages/homebrew.pth
这是用来解决问题的部分。我希望这可以帮助其他人,我要感谢@JoranBeasley 的帮助。