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

安装mysql connector后Python及Anaconda无法启动,导入错误求助

解决安装MySQL Connector后Python/Anaconda无法启动的问题

Hey Ric, let's get your Python and Anaconda back up and running. From the error log you shared, the core issue is that your system Python 3.6 is trying to load SQLAlchemy from your Anaconda package directory, which causes a relative import failure—SQLAlchemy's mysql/types.py uses relative imports that don't work when loaded outside the Anaconda environment context.

Here's how to fix this step by step:

1. Fix the conflicting site-packages path

First, we need to stop system Python from accessing Anaconda's packages:

  • Navigate to your system Python's site-packages folder: C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site-packages
  • Look for .pth files (especially protobuf-3.5.2.post1-py3.6-nspkg.pth mentioned in the error) and open them with a text editor.
  • If any line in these files points to your Anaconda path (like D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages), delete that line. Alternatively, rename the .pth file to something like protobuf-3.5.2.post1-py3.6-nspkg.pth.bak to temporarily disable it.

2. Separate your system Python and Anaconda environments

Conflicting PATH settings often cause this kind of cross-environment mess:

  • Open your system's Environment Variables (search for "Edit the system environment variables" in Windows search).
  • In the PATH variable, check if Anaconda's directories are listed before your system Python 3.6 directories. If so, move the system Python paths to the top, or temporarily remove the Anaconda paths to test if Python starts correctly.
  • For Anaconda usage, always use conda activate to launch the specific environment you need instead of running python.exe directly from the command prompt.

3. Uninstall and reinstall the problematic package

If the path fixes don't work, let's reset the MySQL Connector installation:

  • Open a command prompt and run:
    pip uninstall mysql-connector-python
    
    (If you installed a different variant, use mysql-connector instead of mysql-connector-python.)
  • Next, repair your system Python's core packages with:
    python -m ensurepip --upgrade
    
  • When you need to reinstall MySQL Connector later, make sure you're installing it in the correct environment:
    • For system Python: Use pip install mysql-connector-python
    • For Anaconda: Activate your environment first, then run conda install mysql-connector-python

4. Verify the fix

After completing the steps above:

  • Run python.exe in the command prompt to check if the interactive shell starts normally.
  • Test launching IDLE with python -m idlelib.idle to confirm it works too.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:02:21