ImportError: bad magic number in 'wx': b'\x03\xf3\r\n'

This is Fedora with python3-wxpython4-4.0.6-8 installed.

I tried a sample from the wxpython website:

#!/usr/bin/env python3

# First things, first. Import the wxPython package.
import wx

# Next, create an application object.
app = wx.App()

# Then a frame.
frm = wx.Frame(None, title="Hello World")

# Show it.

# Start the event loop.

and got

ImportError: bad magic number in 'wx': b'\x03\xf3\r\n'

Any ideas?


If I understand this correctly it means that the Fedora package is in error. As I don’t want to mess around with the package in /usr/lib64/python3.7/site-packages/wx/ I cannot use wxPython for now.

Hopefully, the Fedora package gets fixed soon. Perhaps I find out where I could report a bug regarding the Fedora package.

I tried to work around but without success:

  1. I deinstalled the Fedora packages python3-wxpython4 and python3-wx-siplib
  2. Then I installed python3-pathlib2
  3. Finally I installed wxPython for my user which is sufficient for the time being:
    pip-3 install --user wxPython

But the same bad magic number error as before. No idea where there are conflicting .pyc files


1 - install the requisites :

2 - then download " wxPython-4.0.6-cp37-cp37m-linux_x86_64.whl "

3 - finally go to the directory where you downloaded the file,
and try :

sudo pip3 install wxPython-4.0.6-cp37-cp37m-linux_x86_64.whl

Good luck,

It has worked for me on Fedora 30… if you have Fedora 29/28 :
choose the right WHL version of python (cp36 ?..)


Thanks for this.

I did as you suggested. The only difference that I installed for my user, i.e.
pip-3 install --user wxPython-4.0.6-cp37-cp37m-linux_x86_64.whl

But the same bad magic number error persists.

Are you sure that the python you are using to run the wx script matches the version the wheel was built for?

$ /usr/bin/python3 --version
Python 3.7.4
$ /usr/bin/python3 
Traceback (most recent call last):
  File "", line 4, in <module>
    import wx
ImportError: bad magic number in 'wx': b'\x03\xf3\r\n'

1 -
Did you try to clean up your system with deleting the wx directories in :
Before installing the wxPython-4.0.6-cp37-cp37m-linux_x86_64.whl ?

2 -
Can you try the command :
sudo pip3 install wxPython-4.0.6-cp37-cp37m-linux_x86_64.whl

I don’t have (and didn’t have) anything in /usr/local/lib64/python3.7/site-packages. I also checked
/usr/lib64/python3.7/site-packages/wx which didn’t exist.

I tried your suggestion no 2. and it was installed into /usr/local/lib64/python3.7/site-packages:

WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Processing ./wxPython-4.0.6-cp37-cp37m-linux_x86_64.whl
Requirement already satisfied: numpy in /usr/lib64/python3.7/site-packages (from wxPython==4.0.6) (1.17.2)
Requirement already satisfied: six in /usr/lib/python3.7/site-packages (from wxPython==4.0.6) (1.12.0)
Requirement already satisfied: pillow in /usr/lib64/python3.7/site-packages (from wxPython==4.0.6) (6.1.0)
Installing collected packages: wxPython
Successfully installed wxPython-4.0.6

But nevertheless, the bad magic number errror persists

Try :

[aaa@localhost ~]$ python3
Python 3.7.3 (default, May 11 2019, 00:38:04) 
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> print (wx.__version__)

I don’t reach the print statement as the import statement fails already.

The system where things fail is a Fedora 31 beta.

I tried things now on a Fedor 30 by installing the whl file and import wx works ok.

So, either there is a problem related to Fedora31 or there is another system specific problem

Ok, I found the cause of all. It was a beginner’s error on my side.

My first test was to name my test script This caused an error because I am not allowed to use the same name as the installed wx module.

I renamed to but forgot to delete wx.pyc. This caused the import error.

Sorry, that I was so stupid.