Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxpython error on setup - ModuleNotFound: no module named 'wx'

I'm having some trouble getting wxpython working on my mac. Here is a link to a tutorial that I am using: https://realpython.com/python-gui-with-wxpython/#getting-started-with-wxpython

The error message I am receiving is on the import of wx: || receiving ModuleNotFoundError: No module named 'wx' ||

  • I have pip installed wxpython and pip3 installed wxpython just for good measure (sidenote: not sure of the difference, I'll google it) The package is properly shown in ||pip3 list|| terminal command.

I have also tried import wxpython as wx, in case that was an issue. No luck.

I have done some reading on the wxpython.org gitHub and readme, perhaps I missing some dependencies? Here is the prerequisites page: https://github.com/wxWidgets/Phoenix/blob/master/README.rst#prerequisites

They mention some sort of a build and wheel here: https://github.com/wxWidgets/Phoenix/blob/master/README.rst#id2

I consider myself a little more experienced than a beginner at this stuff, but I have never read or heard of such terms above. The most work I have had to do to import some non-standard library was pip3 install x.

import wx
app = wx.App()
frame = wx.Frame(parent=None, title='Hello World')
frame.Show()
app.MainLoop()

Expected result: a blank window with title "Hello World" Actual result: error on line 1... ModuleNotFoundError: No module named 'wx'

like image 688
Ru Ba Avatar asked Oct 29 '25 20:10

Ru Ba


1 Answers

Uninstall using the same pip / pip3 tools, and then use this:

$ python -m pip install wxpython

The -m module syntax ensures that sys.path has the same value during installation as it will at runtime.

If still no joy, then first figure out where the binary wheel got installed to:

$ mdfind wx | egrep '/wx$'

or

$ find ~/miniconda3 ~ /usr / -name wx

(Hit CTRL-C once found.)

Then see if your path is searching in the right place:

$ echo $PYTHONPATH
$ which python
$ python
>>> import pprint
>>> import sys
>>> pprint.pprint(sys.path)
...
>>> import wx
>>> 

The path is controlled by an env var. Consider doing $ export PYTHONPATH=/some/dir before invoking the interpreter.

like image 137
J_H Avatar answered Oct 31 '25 10:10

J_H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!