簡體   English   中英

無法導入wxPython(Mac)

[英]Can not import wxPython (Mac)

我以為我會從使用Tkinter轉到wxPython,但我遇到了一些麻煩。 我得到的就是:

>>> 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的版本匹配:

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.

我在OS X 10.7.5 32位。

任何幫助都是極好的! :)

Mac可以安裝多個版本的Python。 你確定你為使用解釋器調用的同一個python安裝了wxPython嗎?

試試, which python ,並確保這個版本的python在site-packages有一個指向wxPython安裝的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的版本。

我發現同樣的問題。 我用brew install wxpython將它安裝在mac上。 我嘗試上面的方法,但沒有用。 我碰巧在安裝另一個軟件包時找到了解決方案,如下所示:

   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

我有Python 2.7和3.7。 /usr/local/bin/有2.7和3.7 Python版本的符號鏈接以及pip的符號鏈接。

我用pip3安裝了wxPython

pip3 install -U wxPython

然后我檢查了Python3的安裝

myname$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.0.4 osx-cocoa (phoenix) wxWidgets 3.0.5'

安東尼奧

在我的情況下,它通過將brew環境重置為2.7來工作:

brew link --overwrite python@2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM