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

Windows10+PyCharm环境下Python安装hunspell失败求助

解决Windows10 PyCharm中Hunspell安装问题的分步方案

Hey there! Let's work through these hunspell installation headaches on Windows 10 with PyCharm step by step. I've tackled similar frustrating issues before, so here's what you can try to get it working:

1. Fixing the CyHunspell "pkg-config not recognized" Error

That error pops up because pkg-config isn't included with Windows by default, and CyHunspell relies on it to find hunspell libraries during installation. You’ve got two solid paths here:

Option A: Use a Pre-built Wheel File (Quickest Fix)

Instead of compiling from source (which requires all the messy dependencies), grab a pre-compiled .whl file that matches your Python version (e.g., 3.10, 3.11) and 64-bit Windows setup. Then install it directly:

  1. Save the correct .whl file to a folder on your computer
  2. Open PyCharm’s terminal, navigate to that folder with cd path/to/folder
  3. Run this command (replace the filename with the one you downloaded):
    pip install CyHunspell-xxx-cp3xx-none-win_amd64.whl
    

Pro tip: If you’re unsure which version to pick, run python --version in the terminal to check your Python version (e.g., 3.10.x needs a cp310 wheel).

Option B: Install pkg-config & Dependencies (For Source Compilation)

If you want to compile from source, you’ll need to set up the required tools:

  1. Install the MSYS2 toolset (a Windows-compatible Unix-like environment)
  2. Open the MSYS2 terminal and install the necessary packages:
    pacman -S pkg-config hunspell-devel
    
  3. Add the MSYS2 bin folder (usually C:\msys64\usr\bin) to your Windows PATH environment variable
  4. Restart PyCharm completely, then run pip install CyHunspell again

2. Why PyHunspell Installation Fails

PyHunspell is no longer actively maintained, and there are no pre-built packages available for modern Windows or Python versions. Save yourself the trouble and skip this option entirely — CyHunspell or pre-built hunspell packages are way more reliable.

3. Fixing the Direct hunspell Installation Compile Error

When you run pip install hunspell, it tries to compile the package from scratch, which needs hunspell’s development headers and a properly configured C compiler on Windows. This is really finicky to get right, so the pre-built wheel approach (Option 1A) is way easier for most people.

4. Fixing the "AttributeError: module 'hunspell' has no attribute 'HunSpell'" Error

This usually happens if you installed a mismatched or incomplete hunspell package. If you went with CyHunspell, your test code needs to use the correct import and initialization (plus you’ll need language dictionary files):

import cyhunspell
# Replace these paths with your actual .dic and .aff dictionary files (e.g., en_US.dic/en_US.aff)
spellchecker = cyhunspell.HunSpell("path/to/en_US.dic", "path/to/en_US.aff")

Note: You’ll need to download hunspell dictionary files for your language (like English, French) and put them somewhere your script can access. Use the full file path if they’re not in the same folder as your script.

Alternative: Use a Conda Environment (If You’re Using Conda)

If your PyCharm project uses a Conda environment, this simplifies everything. Just run this in the terminal:

conda install -c conda-forge hunspell cyhunspell

Conda automatically handles all the underlying dependencies (like pkg-config and hunspell libraries) so you don’t have to mess with PATH settings or compiler setup.


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

火山引擎 最新活动