1

I installed wxPython version 4.1.1 from pip3 and my python version is 3.8.9 on a M1 processor running MacOS Monterey.

Importing wx results in the following exception:

Traceback (most recent call last):
  File "myPythonProgram.py", line 1, in <module>
    import wx
  File "/Library/Python/3.8/site-packages/wx/__init__.py", line 17, in <module>
    from wx.core import *
  File "/Library/Python/3.8/site-packages/wx/core.py", line 12, in <module>
    from ._core import *
ImportError: dynamic module does not define module export function (PyInit__core)

I tried the following options but none of the following seemed to have worked and the result in the same exception, stated above:

  • Tried wxPython(4.1.1) installation using pip - python3 -m pip install -U --user wxPython==4.1.1
  • Tried wxPython(4.1.2) with pip3 install -U --user ./wxPython-4.1.2a1.dev5259+d3bdb143-cp38-cp38-macosx_11_0_universal2.whl
  • Tried compilation/installation of wxPython from source code

Any hints to resolve the issue?

nhonnava
  • 21
  • 1
  • 5
  • Have you tried `pip3.8 install wxPython==4.1.1` – Freddy Mcloughlan Apr 22 '22 at 04:00
  • @FreddyMcloughlan : Tried it now but it gives the same error – nhonnava Apr 22 '22 at 04:26
  • Same error when running `python3` in the terminal? – BeRT2me Apr 22 '22 at 05:20
  • Try without the `--user` and possibly `-U`. You are upgrading (-U) to a user directory (--user) but the error suggests it's looking in the main directory for wx ("/Library/Python/3.8/site-packages/wx/__init__.py"), See: https://stackoverflow.com/questions/42988977/what-is-the-purpose-of-pip-install-user – Rolf of Saxony Apr 23 '22 at 06:31
  • @RolfofSaxony: Just did a plain `pip3 install wxPython==4.1.1`. Still got the same error. – nhonnava Apr 24 '22 at 08:43
  • @nhonnava Did you remember to un-install the previously installed one in `/Library/Python/3.8/site-packages` ? – Rolf of Saxony Apr 24 '22 at 13:20
  • @RolfofSaxony: Yes. Always starting with a clean slate for all the trials. – nhonnava Apr 25 '22 at 03:30
  • @BeRT2me: Yes, same error even while using python3 in the terminal. – nhonnava Apr 25 '22 at 05:58
  • @nhonnava See this thread if you haven't read it: https://discuss.wxpython.org/t/wxpython-not-installing-via-pip-on-apple-silicon-m1-max/35697/5 – Rolf of Saxony Apr 25 '22 at 06:36
  • `./wxPython-4.1.2a1.dev5259+d3bdb143-cp38-cp38-macosx_11_0_universal2.whl` suggests that you're installing the universal (intel) package of wxpython. But, Which package of python are you running, the intel, or an apple silicon one? You'll need to make sure they match. I second what @RolfofSaxony linked to though, I've had more luck using Conda on the M1 than anything else. You could also try the brew formulae `brew install wxpython` – BeRT2me Apr 25 '22 at 06:42
  • I tried conda and brew, but none of it helped. – nhonnava Apr 27 '22 at 04:47

1 Answers1

0

I'm able to resolve the issue using by executing the following steps:

  1. Install native minforge release from here
  2. Create a virtual environment and install wxpython from mini-forge
  • conda create --name my_env_py38 python=3.8
  • conda activate my_env_py38
  • conda install -c conda-forge wxpython # installs wxPython version 4.1.1
nhonnava
  • 21
  • 1
  • 5