简体   繁体   中英

ModuleNotFoundError when running Python script in anaconda prompt

I am trying to run the following Flask app on Anaconda Prompt

from flask import Flask, flash, redirect, url_for, render_template, request, session, abort
import os
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
from werkzeug import secure_filename


app = Flask(__name__)
app.config.from_object(__name__)
app.run(debug=True)

@app.route('/')
@app.route("/index", methods=['GET', 'POST'])
def index():
if request.method == 'POST':
    return render_template('map.html')
else:
    return render_template('map.html')

if __name__ == "__main__":
    app.secret_key = os.urandom(12)
    app.run(debug=True,host='0.0.0.0', port=4000)

This results in the following error:

(C:\Users\jgpfi_000\Anaconda3) 
C:\Users\jgpfi_000\Documents\housescrapeapp>py app_index.py
Traceback (most recent call last):
    File "app_index.py", line 3, in <module>
        from flask import Flask, flash, redirect, url_for, render_template, request, session, abort
ModuleNotFoundError: No module named 'flask'

I have already installed the module through PIP.

I have tried appending the PATH of the script location using:

sys.path.append(r'C:\Users\jgpfi_000\Documents\housescrapeapp\app_index.py')

but the same error still occurs.

There are usually two versions of Python installed, 2.x and 3.x versions.

If you use pip , the 2.x version's site library will be updated, in order to install the required package with the 3.x version, you can use this:

python -m pip install flask

通过卸载Python 3.7并仅在anaconda提示符下运行python app_index.py即可python app_index.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM