简体   繁体   English

matplotlib.pyplot和wx使用python 2.7.10导入问题

[英]matplotlib.pyplot and wx importing problems using python 2.7.10

I have installed many libraries for a project, but two specific libraries are giving me trouble when trying to import to python. 我已经为一个项目安装了许多库,但是尝试导入python时有两个特定的库给我带来麻烦。 These two are matplotlib.pyplot and wxpython. 这两个是matplotlib.pyplot和wxpython。 I have already followed many tutorial to see how to properly install these packages into python but so far I have had no luck. 我已经按照许多教程进行了介绍,以了解如何将这些软件包正确安装到python中,但到目前为止我还没有运气。 Here is the error that get when trying to import: 这是尝试导入时出现的错误:

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. 

So how do I know that these two libraries have been installed properly and in the desired directory? 那么,我如何知道这两个库已正确安装并位于所需目录中? I know that this might be an easy question to answer but I have been trying for a while to solve this and I also haven't had too much experience with python. 我知道这可能是一个容易回答的问题,但是我已经尝试了一段时间解决了这个问题,而且我对Python也没有太多的经验。 Thanks in advance. 提前致谢。

The problem was solved and the solution was as follow. 问题已解决,解决方法如下。 After I installed wxpython and captured the output using "brew install wxpython> install.log 2>error.log", I figured out that when the wxpython is installed it does not have the proper directory and it also tells you exactly how to change this directory. 安装wxpython并使用“ brew install wxpython> install.log 2> error.log”捕获输出后,我发现安装wxpython时没有正确的目录,它还告诉您确切的更改方法目录。 The captured output looked like follow: 捕获的输出如下所示:

==> 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

So if you look at the above execution you can see: 因此,如果您查看以上执行,您将看到:

   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

This was the part that was used to solve the problem. 这是用来解决问题的部分。 I hope that this can help someone else and I would like to thank @JoranBeasley for his help. 我希望这可以帮助其他人,我要感谢@JoranBeasley的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM