Partially initialized module 'wx' has no attribute '__version__'

I am trying to compile a full featured KiCad on my system using wxWidgets 3.1 to work around this old bug I am experiencing on Linux Mint.

While compiling with wxWidgets 3.1 works fine and solves most of my problems, I want to also compile in Python support.

What I have done:

  • Installed wxPython 4.1.1 via pip install wxPython==4.1.1
  • that dragged in wxWidgets 3.1.5 that is bleeding edge, so I cloned wxWidgets repository and compiled it
  • so far so good, KiCad has compiled with no problems, I can run it

Now when I try to start python console I get

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/miceuz/kicad/share/kicad/scripting/kicad_pyshell/", line 17, in <module>
    import wx
  File "/usr/local/lib/python3.8/dist-packages/wx/", line 12, in <module>
    __version__ = wx.__version__.VERSION_STRING
AttributeError: partially initialized module 'wx' has no attribute '__version__' (most likely due to a circular import)

I have a single version of wxPython installed that is in /usr/local/lib/python3.8/dist-packages/wx/ my PYTHONPATH points to local kicad install directory: /home/miceuz/kicad/usr/share/kicad/scripting

I can import wx from python3.8 console with no problems, also running python /home/miceuz/kicad/share/kicad/scripting/kicad_pyshell/ gives no errors.

Now there are references about this problem here and there and all of them are a bit cryptic, one solution was refered as “uninstall wxPython from pip and do apt install python-wx” and another one says

Python3 is trying to import /usr/local/lib/python3.6/dist-packages/wx/
It’s on your /usr/local directory so it is not owned by packages of your distribution.
Remove your /usr/local… installation of wx and use python3-wxgtk4.0 from the distribution.

Can anyone explain to me the root cause of this problem and how can I fix it? Where does the KiCad python console expect wxPython to be located?

I have tried to hack it a bit by hardcoding the version string in wx/

import wx.__version__
__version__ = '4.1.1' #wx.__version__.VERSION_STRING

But now I get a different error while trying to start python console:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/miceuz/kicad/share/kicad/scripting/kicad_pyshell/", line 17, in <module>
    import wx
  File "/usr/local/lib/python3.8/dist-packages/wx/", line 17, in <module>
    from wx.core import *
  File "/usr/local/lib/python3.8/dist-packages/wx/", line 12, in <module>
    from ._core import *
ImportError: /usr/local/lib/python3.8/dist-packages/wx/ undefined symbol: _ZN13wxWindowIDRef6AssignEi, version WXU_3.1

First of all, don’t do any manual hacks to system packages, that’s a rabbit hole that will not end up anywhere good.
Second, verify that you have only one python or that at least what get’s invoked when you type “python” in console and what cmake cached as python location (look for PYTHON_EXECUTABLE in cmakecache.txt in build directory) are the same.

I don’t quite understand what this means

what do you mean by “dragged in” ? pip wouldn’t install wxwidgets, it’s not a python package.

In general I’m not sure that wxpython that you got from pip will play nicely with your custom wxwidgets. You may have to uninstall that and compile wxpython yourself and link it against your custom wxwidgets.

Yeah, I know, that hack was just to see what happens if trivial error is avoided.

I am sure it’s the same python that’s getting invoked - python3.8

At first I have compiled wxWidgets release 3.1.4, but pip install wxPython==4.1.1 takes a long time, it’s compiling something in the background and apearently that is wxWidgets 3.1.5 related because when I have tried cmaking kicad it complained that at least 3.1.5 is required. Then I cloned xwWidgets repo and build that, after this cmake was happy.

Try reinstalling wxpython if it compiles something it should link against your wxwidgets.

I have tried re-installing wxPython after compiling and installing wxWidgets. Also wxPython works just fine - it can create an application window, etc.

If wxpython works separately but not in kicad that means there is some difference in environment. Unfortunately it’s not trivial to troubleshoot. I would start by inspecting what sys.path is in python in terminal and in python in kicad. To do the latter you will likely have to inject some code somewhere here. You should be able to print to stdout or of that’s not captured at that stage then write to a text file for debug.

Hi, thanks for your suggestions. I have successfully injected:

    pcbnew_pyshell_one_step << "import sys\n";
    pcbnew_pyshell_one_step << "print(sys.path)\n";
    pcbnew_pyshell_one_step << "import kicad_pyshell\n";
    pcbnew_pyshell_one_step << "import wx\n";

In KiCad:


In python3:


Unfortunately I don’t see anything out of ordinary - none of paths that are in KiCad contain any wx directories or files except for /usr/local/lib/python3.8/dist-packages where wxWidgets was installed by pip

I have tried one experiment:

 ~/kicad/bin $ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path=['/home/miceuz/kicad/bin', 
... '/home/miceuz/kicad/usr/share/kicad/scripting', 
... '/home/miceuz/kicad/lib/python3/dist-packages', 
... '/usr/lib/', 
... '/usr/lib/python3.8', 
... '/usr/lib/python3.8/lib-dynload', 
... '/home/miceuz/.local/lib/python3.8/site-packages', 
... '/usr/local/lib/python3.8/dist-packages', 
... '/usr/lib/python3/dist-packages', 
... '/usr/lib/python3.8/dist-packages', 
... '.', 
... '/home/miceuz/kicad/share/kicad/scripting', 
... '/home/miceuz/kicad/share/kicad/scripting/plugins', 
... '/home/miceuz/.config/kicad/5.99/scripting', 
... '/home/miceuz/.config/kicad/5.99/scripting/plugins']
>>> import kicad_pyshell
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/miceuz/kicad/share/kicad/scripting/kicad_pyshell/", line 24, in <module>
    import pcbnew
  File "/home/miceuz/kicad/lib/python3/dist-packages/", line 15, in <module>
    import _pcbnew
ImportError: /home/miceuz/kicad/lib/python3/dist-packages/ undefined symbol: _ZN14wxPlatformInfo14GetBitnessNameE9wxBitness, version WXU_3.1

Am I correct to interpret this that does not know anything about WXU_3.1 symbols anyway?

This is ldd output:

ldd /home/miceuz/kicad/lib/python3/dist-packages/ (0x00007ffc22be0000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdfc93000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdfbe3000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdfb00000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdf22d000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdf1c8000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdeeff000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdedea000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdedd6000) => /home/miceuz/Downloads/wxWidgets/buildgtk/lib/ (0x00007fafdeb13000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafde57d000) => /home/miceuz/Xaltura/kicad/build/release/3d-viewer/3d_cache/sg/ (0x00007fafde50e000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafddd5b000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafddc38000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafddbd8000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafddaaf000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdda1e000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdda09000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd960000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd8d8000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd866000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd685000) => /lib/x86_64-linux-gnu/ (0x00007fafdd536000) => /lib/x86_64-linux-gnu/ (0x00007fafdd51b000) => /lib/x86_64-linux-gnu/ (0x00007fafdd4f6000) => /lib/x86_64-linux-gnu/ (0x00007fafdd304000)
	/lib64/ (0x00007fafe1eb0000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd1ff000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd1fa000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd1e9000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd1d5000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd186000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdd15e000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdcf7d000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdce40000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdce39000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdce2c000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdcc26000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdcc0d000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdcbc6000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdcb8e000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdcb09000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdca86000) => /lib/x86_64-linux-gnu/ (0x00007fafdca6a000) => /lib/x86_64-linux-gnu/ (0x00007fafdca64000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdca03000) => /lib/x86_64-linux-gnu/ (0x00007fafdc9da000) => /lib/x86_64-linux-gnu/ (0x00007fafdc9aa000) => /lib/x86_64-linux-gnu/ (0x00007fafdc9a5000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc99f000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc98d000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc985000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc977000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc94d000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc916000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc7e3000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc7c6000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc6c1000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc600000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc5fb000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc5d1000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc5c2000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc3b8000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc3a3000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc395000) => /lib/x86_64-linux-gnu/ (0x00007fafdc322000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc2f9000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc2d8000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc2b8000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc248000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc235000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdc1a2000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbecc000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbe7f000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbe29000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbe18000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbe08000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbd50000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbd1c000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbd17000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbd0a000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbcfb000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbcf6000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbcf1000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbcaf000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbca4000) => /lib/x86_64-linux-gnu/ (0x00007fafdbc99000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbc8c000) => /lib/x86_64-linux-gnu/ (0x00007fafdbc2c000) => /lib/x86_64-linux-gnu/ (0x00007fafdbc01000) => /lib/x86_64-linux-gnu/ (0x00007fafdbbe5000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdbbc7000) => /lib/x86_64-linux-gnu/ (0x00007fafdbbbc000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb953000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb8aa000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb69c000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb57e000) => /lib/x86_64-linux-gnu/ (0x00007fafdb52b000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb4f4000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb4c7000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb4c1000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb4b9000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb335000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb15f000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb127000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb0ed000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdb069000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaf8a000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaf59000) => /lib/x86_64-linux-gnu/ (0x00007fafdaf52000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaf43000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaf26000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaee1000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaebc000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaeb2000) => /lib/x86_64-linux-gnu/ (0x00007fafdae5b000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdadcb000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdadb1000) => /lib/x86_64-linux-gnu/ (0x00007fafdad8c000) => /lib/x86_64-linux-gnu/ (0x00007fafdacdd000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaba7000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdab91000) => /lib/x86_64-linux-gnu/ (0x00007fafdab8a000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdab7c000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaae9000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaa42000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafdaa0a000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafda9f1000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafda9ce000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafda9a4000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafda992000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafda944000) => /usr/lib/x86_64-linux-gnu/ (0x00007fafda81b000) => /lib/x86_64-linux-gnu/ (0x00007fafda7e0000)

I believe you need to add location of to LD_LIBRARY_PATH to make it load properly. The error message may be misleading.

Regarding initial issue, this message partially initialized module 'wx' has no attribute '__version__' is usually not the first error, it happens on repeated attempt to import wx. Do you see any errors before that? Try launching pcbnew standalone from terminal to filter out irrelevant things. Pcbnew loads scripting on init. You can force it to import wx right away by adding a dummy script that does just that to ~/.kicad/scripting/plugins

Thanks for bearing with me, but the true mystery will be left unsolved. I dug deeper into wxpython code to find out that my wxwidgets build was missing some features, I have tried re-compiling it, to stumble on another thing that’s missing.

Finally I have uninstalled wxWidgets and wxPython, then cloned and built bleeding edge version of wxPython - it does compile wxWidgets also. And BAM, I have a working python console and the whole KiCad build on wxWidgets 3.1.

Glad you got it working.
But did it fix your Mint related GUI issues?

Yes it did, almost - it’s all reported in the issue linked above. All text field related issues are fixed, but Appearance manager’s Objects tab gets butchered if I change tabs. I.e. if Objects tab is the last one to be open and I close and start pcbnew (pcbnew remembers last tab that was open in Appearance manager) - it works fine, but if I change to other tab, say, “Layers” and then back to “Objects” - it’s totally butchered. I have tried poking around in the code around this place - nothing suspicious and MacOS workarounds don’t give any noticeable effect.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.