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

Mac终端运行python run.py报错:找不到flask_restful模块

Fixing "ModuleNotFoundError: No module named 'flask_restful'" on Mac

Hey there, let's work through this frustrating error together. The issue almost always boils down to a mismatch between which Python interpreter you're using to run your script and which one you installed flask_restful into. Here's how to troubleshoot step by step:

1. Verify Python and pip version alignment

Macs come pre-installed with Python 2.7 by default, but if you've installed Python 3 (which you probably have), you might be mixing up python/pip (Python 2) and python3/pip3 (Python 3).

  • First, check which Python you're running:
    python --version
    
  • Then check which pip is associated with it:
    pip --version
    

If the versions don't match (e.g., Python 3.9 but pip points to Python 2.7), that's the problem. Try running your script with python3 instead:

python3 run.py

And if you haven't installed flask_restful for Python 3 yet, use:

pip3 install flask-restful

2. Confirm the package is installed in your active environment

Run this command to list all packages installed for your target Python interpreter:

# For Python 2
python -m pip list
# For Python 3
python3 -m pip list

Look for flask-restful (note the hyphen here — pip uses hyphens, but imports use underscores). If it's not listed, install it using the -m pip method to ensure it goes to the right interpreter:

python3 -m pip install flask-restful

3. Check for virtual environment issues

If your project uses a virtual environment (like venv, virtualenv, or Conda), you need to activate it before installing packages or running your script.

  • For a standard venv setup:
    source /path/to/your/venv/bin/activate
    

Once activated, install the package again (even if you think you did before) and run your script:

pip install flask-restful
python run.py

4. Use the full path to your Python interpreter

If all else fails, find the exact path to your Python 3 interpreter:

which python3

You'll get something like /usr/local/bin/python3. Use this full path to install the package and run your script:

/usr/local/bin/python3 -m pip install flask-restful
/usr/local/bin/python3 run.py

To recap, your error looks like this:

$ python run.py
Traceback (most recent call last):
File "run.py", line 17, in
app = create_app("config")
File "run.py", line 7, in create_app
from app import api_bp
File "/Users/userName/Backend/app.py", line 2, in
from flask_restful import Api
ModuleNotFoundError: No module named 'flask_restful'

This is almost certainly a version/environment mismatch — the steps above should get you sorted.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 08:52:47