You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在Conda Python 2环境中安装wxPython 3并解决安装异常

Alright, let's break down your problem into two clear parts: installing wxPython 3 in your Conda Python 2 environment, and fixing the issue where Conda doesn't recognize the wxPython you installed via brew. Here's how to tackle each step:

Installing wxPython 3 in Your Conda Python 2 Environment

First, make sure you're actively working in your Python 2 Conda environment. For newer Conda versions:

conda activate your_py2_environment_name

For older Conda versions (pre-4.6):

source activate your_py2_environment_name
  • Option 1: Use conda-forge (cleanest method)
    Conda-forge maintains a library of legacy packages, including older wxPython builds compatible with Python 2. Try running this command:

    conda install -c conda-forge wxpython=3.0
    

    If this succeeds, you're all set! This installs wxPython 3.0 directly into your isolated Conda environment, avoiding conflicts with system or other Python setups.

  • Option 2: Install from SourceForge source code (if conda-forge fails)
    The pre-built installers from SourceForge are tied to your system's default Python, which is why you saw those confusing errors. Instead, use the source package to install directly into your Conda environment:

    1. Download the wxPython 3.0 source archive for Python 2 from SourceForge (pick the version matching your OS).
    2. Extract the archive, then navigate to the extracted folder in your terminal.
    3. With your Conda environment activated, run:
      python setup.py install
      
      This compiles and installs wxPython 3.0 directly into your Conda environment's site-packages directory, so it's only available to this environment.

Fixing Conda Not Recognizing Brew-Installed wxPython

The core issue here is that Conda environments are fully isolated from your system's Python (including brew-installed packages). Conda's Python only looks for packages in its own environment's site-packages folder, not the system-wide location where brew installs software.

You have two choices:

  • Option 1: Avoid this entirely (highly recommended)
    Stick with the methods above to install wxPython 3.0 directly into your Conda environment. This keeps your environment clean and prevents dependency conflicts between system and Conda packages.

  • Option 2: Force Conda to recognize the brew package (last resort)
    If you absolutely need to use the brew-installed version, you can add the system site-packages path to your Conda environment's Python path:

    1. Activate your Conda environment.
    2. Run this command to find your system Python's site-packages location:
      python -c "import sys; print([p for p in sys.path if 'site-packages' in p and not 'conda' in p][0])"
      
    3. Navigate to your Conda environment's site-packages directory (find it with python -c "import site; print(site.getsitepackages()[0])").
    4. Create a new file named wx_brew.pth (the name doesn't matter as long as it ends with .pth), and paste the system site-packages path you found into it.
    5. Restart your Python session in the Conda environment—it should now detect the brew-installed wxPython.

    Note: This can cause unexpected conflicts if system packages and Conda packages are incompatible, so only use this if you have no other option.


A quick side note: The reason pip isn't working is that wxPython 4.x dropped Python 2 support, and the 3.0 versions were removed from PyPI. So pip install wxpython defaults to the latest 4.x version, which won't work with your Python 2 environment—hence why you need the Conda or source installation methods above.

内容的提问来源于stack exchange,提问作者HappyFace

火山引擎 最新活动