You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win10系统Python3.6环境下,如何解决‘No module named pymysql’报错?

Troubleshooting "No module named 'pymysql' / MySQLdb" Errors on Windows 10 (Python 3.6)

Hey there, let's work through why you're hitting those frustrating "module not found" errors even after installing the packages. Here are the most common fixes to try out:

1. Ensure you're installing packages for your actual Python 3.6 instance

Windows often has multiple Python versions floating around (system defaults, Anaconda, separate 3.6/3.9 installs, etc.). It’s super easy to install packages to one version but run your code with another.

  • Open Command Prompt and run python --version to confirm which Python your terminal is using. If it’s not 3.6, target your Python 3.6 directly:
    • Use the full path to your Python 3.6 executable (e.g., C:\Python36\python.exe -m pip install pymysql)
    • Or use the Python Launcher for Windows: py -3.6 -m pip install pymysql (this works if you enabled the launcher during Python 3.6 installation)
  • Verify the installation worked by running py -3.6 -c "import pymysql; print('Success!')" — if no error pops up, the module is installed correctly for 3.6.

2. Fix MySQLdb compatibility for Python 3.6

Important note: MySQLdb is a Python 2-only library — it does NOT support Python 3.x. Any "MySQLdb" installation you see likely isn’t the real thing, or won’t work properly with your 3.6 setup. Here’s how to fix this:

  • If your code uses import MySQLdb, replace it with pymysql and add this line at the top of your script to make pymysql act as a drop-in replacement for MySQLdb:
    import pymysql
    pymysql.install_as_MySQLdb()
    
  • Alternatively, install mysqlclient — the official Python 3-compatible successor to MySQLdb. For Windows 10 + Python 3.6, you’ll need a pre-built wheel file (compiling from source is tricky):
    1. Grab the correct .whl file (matching your system’s 32/64-bit architecture and Python 3.6) from the unofficial Windows binaries repository
    2. Install it via pip: py -3.6 -m pip install path\to\mysqlclient-xxx.whl

3. Check your IDE’s interpreter configuration

If you’re using an IDE like PyCharm or VS Code, it might be using a different Python interpreter than your terminal:

  • In PyCharm: Go to File > Settings > Project: [Your Project] > Python Interpreter. Make sure the selected interpreter is Python 3.6, and check that pymysql (or mysqlclient) appears in the installed packages list. If not, click the + button to install it directly in the IDE.
  • In VS Code: Open the command palette (Ctrl+Shift+P), select Python: Select Interpreter, and choose your Python 3.6 installation. Then run pip install pymysql in the integrated terminal (it will use the selected interpreter).

4. Double-check pip’s target version

Run pip --version in your terminal. The output should show it’s associated with Python 3.6 (e.g., pip 21.3.1 from C:\Python36\lib\site-packages\pip (python 3.6)). If it points to a different Python version, use python3.6 -m pip instead of plain pip to install packages.

Give these steps a shot — one of them should get your modules working properly!

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:08:48