Flask-RESTful报错:No module named 'config'问题求助
Hey there, I’ve run into similar quirky issues with older package versions before—let’s get this sorted out for you.
First, to answer your direct question: Yes, you can safely delete that unused import config line from flask_restful's __init__.py. Since you confirmed the import isn’t actually used anywhere in the code, removing it won’t break any functionality of flask-restful.
Here are your full solution options, ordered by how recommended they are:
Option 1: Upgrade flask-restful (Most Recommended)
Version 0.3.6 is pretty outdated—this config import bug was almost certainly fixed in later releases. Upgrading is the cleanest way to avoid this and other potential issues:
pip install --upgrade flask-restful
After upgrading, you won’t have to mess with the package's source code at all.
Option 2: Remove the Unused Import Line
If you need to stick with version 0.3.6 for some reason, follow these steps:
- Find the location of your flask-restful installation in your conda env. For your setup, it’ll be something like:
my_env/lib/python3.5/site-packages/flask_restful/ - Open the
__init__.pyfile in that directory. - Locate and delete the line that says
import config. - Save the file, and your import from
flask_restfulshould work without errors.
Option 3: Temporary Workaround (Not Recommended)
As a quick fix without modifying package files, you can create an empty config.py file in the root directory of your Flask project. This will satisfy the import requirement, but it’s a hack and might mask other issues with the outdated package version.
内容的提问来源于stack exchange,提问作者Euler_Salter

