如何在macOS High Sierra上安装wxGTK 3.0.20、wxPython 3.0.2.0及wxWidgets?
Hey there! Let's walk through getting these components set up on your High Sierra system. I've worked through similar legacy setup issues before, so here's a detailed, step-by-step guide to help you out:
Prerequisites First
Before diving in, make sure you have these basics covered:
- Install Xcode Command Line Tools: Run
xcode-select --installin Terminal and follow the prompts. - Install Homebrew (if you don't already have it):
Note: High Sierra is an older macOS version, so Homebrew might prompt you to switch to a legacy branch if needed—just follow the on-screen instructions./usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Step 1: Install GTK+3 and Dependencies
wxGTK relies on GTK+3, so let's install that first along with essential build tools:
brew install gtk+3 pkg-config libpng jpeg
This will pull in all the core libraries needed for compiling wxGTK.
Step 2: Compile and Install wxGTK 3.0.20
Since Homebrew doesn't package this specific older version of wxGTK, we'll build it from source:
- Download the wxWidgets 3.0.20 source archive (you can grab this from the wxWidgets official releases page, look for the
.tar.bz2package) - Extract the archive in your Terminal:
tar -xjf wxWidgets-3.0.20.tar.bz2 cd wxWidgets-3.0.20 - Configure the build for GTK+3 (we'll install it to
/usr/localfor system-wide access):
TheCC=clang CXX=clang++ ./configure --with-gtk=3 --prefix=/usr/local --enable-unicode --enable-debug=no --enable-sharedCCandCXXflags ensure we use Clang, which is the recommended compiler for macOS. - Compile and install (the
-j4flag uses 4 CPU cores—adjust this based on your machine's specs):make -j4 sudo make install - Verify the installation by checking the wx-config version:
It should outputwx-config --version3.0.20.
Step 3: Install wxPython 3.0.2.0
A quick heads-up: wxPython 3.0.2.0 is officially built against wxWidgets 3.0.2, so there's a minor version mismatch here that could cause subtle compatibility issues. If possible, consider pairing wxPython 3.0.2.0 with wxGTK 3.0.2 instead. But if you need the exact versions specified, proceed with these steps:
- Download the wxPython 3.0.2.0 source archive for macOS High Sierra (look for the package targeted at 10.13 in the wxPython archives)
- Extract and navigate to the source directory:
tar -xjf wxPython-3.0.2.0.tar.bz2 cd wxPython-3.0.2.0 - Set up the environment so the build system can find wxGTK:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig - Install wxPython (note: this uses the system's default Python 2.7, which wxPython 3.0.2.0 supports—Python 3 compatibility isn't guaranteed here):
sudo python setup.py install
Step 4: Test Your Installation
To confirm everything works, open a Python shell and run this simple test script:
import wx app = wx.App() frame = wx.Frame(None, title="wxPython GTK Test") frame.Show() app.MainLoop()
If a small window titled "wxPython GTK Test" pops up, you're all set!
Troubleshooting Tips
- If you run into compile errors, double-check that all dependencies from Step 1 are installed.
- If wx-config isn't found after installing wxGTK, add
/usr/local/binto your PATH withexport PATH="/usr/local/bin:$PATH". - For version mismatch warnings between wxGTK and wxPython, consider downgrading wxGTK to 3.0.2 to match wxPython 3.0.2.0—just adjust the source download to the 3.0.2 release.
内容的提问来源于stack exchange,提问作者c1der c1der

