PyCharm cannot load wxversion

Hi all!

I am new to Python and wx, and want to run a GUI for a science software package. It requires matplotlib, and that apparently requires wxversion.

Could someone please help with the following issue:

wxversion is working fine if I open Python from the terminal:

Thomass-MacBook-Pro-2:GUI$ python
*Python 2.7.18 (default, Sep 6 2020, 14:59:50) *
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import wxversion

However, using PyCharm directly (Python console), it does not find it.

/usr/bin/python2.7 “/Applications/PyCharm” --mode=client --port=58444
import sys; print(‘Python %s on %s’ % (sys.version, sys.platform))
sys.path.extend([’/Users/… /libRadtran-2.0.3/GUI’])
PyDev console: starting.
*Python 2.7.16 (default, Jan 27 2020, 04:46:15) *
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
import wxversion
Traceback (most recent call last):

  • File “”, line 1, in *
  • File “/Applications/PyCharm”, line 21, in do_import*
  • module = self._system_import(name, *args, *kwargs)
    ImportError: No module named wxversion


The wxversion module no longer exists, starting in wxPython 4.0. See the note in the Migration Guide about it.

In your case, it looks like you are using two different Python instances in your examples above (2.7.18 and 2.7.16) so it is likely that each has their own copy of wxPython, one that is >=4.0 and one that is not. You can print sys.prefix in each case to see where they are located.

It is best to ensure that you are using the same instance of Python when running from the command line and inside of IDEs. That way you can make sure that the same version of installed packages are being used. Using virtual environments are a great way to do that. Then you can activate the venv in both cases and know you have the same environment and installed packages in all cases.

If you want to use wxPython4 then you will probably need to upgrade your version of matplotlib to get one that does not require the wxversion module. If you’re able then it would be a good idea to upgrade to Python3 as well. Python 2.7 has reached end-of-life, and many of the common 3rd-party packages have stopped supporting it as well.

Many thanks;
you are correct!

It was all due to a version mixup, which I caused myself. I uninstalled all Python packages using MacPorts, and then I discovered that I somehow I had installed a 4.0 version of wxPython directly (not using MacPorts). I used PIP to uninstall that wxPython version, and made a fresh install of 2.7 compatible packages; and the code worked

Many thanks,.