我为项目安装了许多库,但是在尝试导入到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的经验。提前致谢。
答案 0 :(得分:1)
问题解决了,解决方法如下。安装wxpython并使用&#34; brew install wxpython&gt;捕获输出后install.log 2&gt; error.log&#34;,我发现当安装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的帮助。