Reputation: 333
I am trying to learn Flask, I use Ubuntu 19.04 and I am writing code in VSCode. After following the attached tutorial, I keep having the problem: unresolved import"flask_mysqldb" and the same with wtforms and passlib.
I have installed all requirements, and just to check, I try to install again and I receive the message:'Requirement already satisfied: mysqlclient in "someplace"/.local/lib/python2.7/site-packages
I thought that maybe I am using python 3.7 but it installs itself in 2.7? But it never asked me where to install.
This is the video tutorial I am following: https://www.youtube.com/watch?v=addnlzdSQs4
from flask import Flask, render_template, flash, redirect, url_for, session, loggin
from data import Articles
from flask_mysqldb import MySQL
from wtforms import Form, StringField, TextAreaField, PasswordField, validators
from passlib.hash import sha256_crypt
the first two imports work just fine, the others are underlined with green and receive error messages.
ex:
unresolved import 'flask_mysqldb'
unresolved import 'wtforms'
unresolved import 'passlib.hash'
Upvotes: 12
Views: 34030
Reputation: 2707
I stumbled across this issue while using VSCode with python3 venv.
Premise: While @truth answer pointed me in the right direction, I still could not select the correct interpreter: the right one for me would have been the one created in my venv folder but it wasn't shown on the venv options and even if I browsed to the right folder via the GUI it won't allow me to choose it (because it is a symlink perhaps?)
TLDR: For mac users like me that have python2 installed by default, python3 installed via brew and are using a virtual environment (spawned with python3 -m venv
), the solution is the following:
code .
Done, your dependencies should now resolve.
Upvotes: 6
Reputation: 131
I have had this problem several times and it often works with just "exiting" VSCode since VSCode sometimes doesnt check the path. It uses the "old" settings or "path". By exiting the program and restarting it it updates this and it works (if its this problem)
Upvotes: 13
Reputation: 1
Probably, You used command pip install flask-wtf, but it's wrong way. First You have to use command : sudo apt install python3-pip, and next install flask-wtf with command : pip3 install flask-wtf, because you need libraries for python3, not for python2.
Upvotes: -2
Reputation: 333
After trying many things and not working ,ended up restarting everything. Erased all the files and did it again. Somehow it worked. Must have been some mistake while setting up.
Upvotes: 2
Reputation: 1186
Have you tried to set the interpreter in VSCode to correct value (including your virtualenv if you have one)?
Open the command palette (Ctrl-Shift-P) and choose "Python: Select Interpreter".
For more details, see: https://code.visualstudio.com/docs/python/environments
Upvotes: 25