无法导入wxPython(Mac)
我以为我会从使用Tkinter转移到wxPython,但我遇到了一些麻烦。我得到的是这样的:无法导入wxPython(Mac)
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wx
我已经安装了wxPython。当我运行卸载我清楚地看到,已安装的wxPython:
1. wxPython3.0-osx-cocoa-py2.7 3.0.0.0
Enter the number of the install to examine or 'Q' to quit:
当我开始Python中我看到,我的版本应该匹配的wxPython的版本:在OS X 10.7
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
我.5 32位。
任何帮助将会很棒! :)
Mac可以安装多个版本的Python。你确定你安装了wxPython作为你用解释器调用的同一个python吗?
尝试,which python
,并确保此版本的python在指向wxPython安装的site-packages
中有一个wxredirect.pth
文件。 (如果没有搜索wxredirect.pth
)
这里是我的系统上的一个版本...
> which python2.6
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
> more /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wxredirect.pth
import site; site.addsitedir('/usr/local/lib/wxPython-3.0.0.0/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-2.9.1.1/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.6')
这里,顺便说一句,我可以注释掉wxredirect.pth
线路选择的wxPython我的版本想用。
是的 - 关于loking的好消息wxredirect.pth – GreenAsJade
谢谢你的回答。我在哪里可以找到网站包?我在查找器中搜索,但没有找到这样的文件。我对整个编码事物都很陌生,而且我一直都在使用Windows。 – Halvurd
'site-packages'是一个标准目录,其中不包含标准分发的包(你也应该在Windows中有'site-packages'目录,顺便说一句)。我的搜索器显示在搜索器中,但这可能是由于Finder设置。在类似于我的路径上查找:使用'which python',从该目录备份(到'bin'上的目录)和'lib'等。 – tom10
我只是发现了同样的问题。 我用brew install wxpython
在Mac上安装它。 我尝试了上面的方法,但没用。 我碰巧找到解决办法,当我安装的软件包,它下面showen:
brew install tbb
Downloading https://homebrew.bintray.com/bottles/tbb-2017_U7.sierra.bottle.t
############################################################ 100.0%
==> Pouring tbb-2017_U7.sierra.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/ningrongye/.local/lib/python2.7/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-
packages")' >> /Users/ningrongye/.local/lib/python2.7/site-
packages/homebrew.pth`
这是自制的说,我只是尝试的,和它的作品。
ningrong
的[无法导入Mac OS X上WX(蟒蛇)]
可能重复(http://*.com/questions/4798759/cant-import-wxpython-on-mac-os- x) – hivert
使用该帖子中给出的命令运行python并不能解决我的问题。 – Halvurd
由于苹果的预装python,Mac上的wxpython有点麻烦。你确定你正在运行你安装了wx的python实例吗? – GreenAsJade