how to fix flask import eror (there is no Flask in flask) - python-3.x

i installed flask in the cmd using the pip install flask command and i also tested it in the cmd and it works.
But when i go to pycharm all the modules i download using pip are for some reason in lib/site_packages
instead of just being in site_packages.the lib folder
and then i do "from flask import Flask"
and it says that " cannot import name 'Flask' from 'flask' (C:\Users\User\PycharmProjects\pythonProject1\flask.py)"
the error
there is no Flask in flask

Change the py file name to anything else. naming your flask file as flask.py will create a namespace conflict.

Related

ModuleNotFoundError: No module named 'flask_wtf' ... verified installed in virtualenv

My import statements are as follows:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired
I am able to execute the file - blank.py - within Pycharm and do not receive a ModuleNotFoundError.
Whenever I execute flask run in terminal I get ModuleNotFoundError: 'flask_wtf' and it traces back to 'blank.py'.
I am not sure why this is happening as I have both flask and flask-wtf installed globally and locally. I have never had this problem when working with other libraries.
How do I fix this? Thank you for you help.

Getting a ModuleNotFound error with flask in python

I installed the flask module via following command.[![cmd image][1]][1]
When I ran the following code.
from flask import Flask, render_template
app = Flask(__name__)
#app.route('/')
def index():
#a = input('Enter name')
return render_template(r'form.html')
if __name__ == "__main__":
app.run(debug=True)
It gave an error.
ModuleNotFoundError: No module named 'flask'
Note:- I am not using virtualenv. And I am having my html page in templates folder
[1]: https://i.stack.imgur.com/t4XzJ.png
It seems you have installed flask on the system wide environment. To access the flask in your virtualenv, you have to get into the virtualenv directory and activate it by using following command.
source virtual_env_name/bin/activate
replace 'virtual_env_name' with the virtualenv name you created.
After that in your command line, you will get (virtual_env_name) added before. the current directory path.
Now you can install the flask framework using pip3.
pip3 install flask
Keep in mind to activate venv everytime you are using the flask.

flask_sqlalchemy module cant be found error

So I want to use the flask_sqlalchemy module in my web app. But when I run "flask run" it gives me the following error:
from flask_sqlalchemy import
SQLAlchemy
ModuleNotFoundError: No module
named 'flask_sqlalchemy'
I am running this in a virtual env with python3.7 and pip3. It says that all packages have been installed. Ive tried a whole bunch of things with no luck.
So after trying a whole bunch of stuff. Setting the environment variable FLASK_ENV=development and then to production somehow fixed.

ImportError: No module named flask using MAC VSCODE

ScreenGrab of error when trying to import db I created
You either need to install Flask from pip, or something similar, or Python is not able to find the location of Flask if it is, in fact, installed.
At your Python prompt, try this to see where it is looking for libraries:
>> import sys
>> print (sys.path)

Django 2.1.1 don't find Module pytz

I am trying to deploy a new Django application on an apache web server. The wsgi configuration works fine. However, when ever I try to open the application I run into an internal server error. The log says:
django/utils/timezone.py
import pytz
ModuleNotFoundError: No module named 'pytz'
However, when I do:
python
import pytz
print(pytz.__version__)
everything works fine.
Any ideas ?
///Edit:
Forgot to mention that I am using python3.6 and Django2.1.1
Try to add pytz in your INSTALLED_APPS in settings.py and in your requirements.txt.

Resources