简体   繁体   中英

ModuleNotFoundError: No module named 'wtforms' (VScode venv)

Having problems importing wtforms in vscode Venv and would appreciate some help.

My import statements:

from wtforms import Form, BooleanField, StringField, PasswordField, validators
from flask_wtf import Form
from flask_wtf import FlaskForm

Console output:

ModuleNotFoundError: No module named 'wtforms'

Flask and wtforms are installed:

pip install -U WTForms
 Requirement already satisfied: WTForms ...
pip install -U flask-wtf 
 Requirement already satisfied: flask-wtf in ...

Any ideas?

Create your virtual environment in vs code

  1. Go to menu File → Preferences → Settings.
  2. Click on Workspace settings.
  3. Under Files:Association, in the JSON: Schemas section, you will find Edit in settings.json. Click on that.
  4. Update "python.pythonPath": "Your_venv_path/bin/python" under workspace settings. (For Windows): Update "python.pythonPath": "Your_venv_path/Scripts/python.exe" under workspace settings.
  5. Restart Visual Studio Code in case if it still doesn't show your venv.

Than

pip install -U WTForms

pip install -U flask-wtf

And your import statement is right .

Create your virtual environment in Windows

  1. Open a command line interface (CLI)

C:\\Users\\Owner> cd desktop

C:\\Users\\Owner\\desktop>

  1. Creating a Python virtual environment in Windows

C:\\Users\\Owner> cd desktop

C:\\Users\\Owner\\desktop> py -m venv env

  1. View the virtual environment

C:\\Users\\Owner\\desktop> dir

...

...

05/13/2020 06:40 PM env

  1. How to activate a Python virtual environment in Windows

C:\\Users\\Owner\\desktop> cd env

C:\\Users\\Owner\\desktop\\env> Scripts\\activate

(env)C:\\Users\\Owner\\desktop\\env>

  1. Deactivate the virtual environment

(env)C:\\Users\\Owner\\desktop\\env> deactivate

C:\\Users\\Owner\\desktop\\env>

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