I'm really new to Python and I'm trying to do a tutorial on using flask. When I run the below code:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def home():
return "Hello, World!"
I get the following error message:
Traceback (most recent call last):
File "/Users/myname/Documents/PycharmProjects/flask/test_webapp.py", line 1, in <module>
from flask import Flask
ModuleNotFoundError: No module named 'flask
This doesn't make any sense to me as when I run:
python -m pip list
Flask 1.1.1 is on the list.
I am using Python version 3.7.4.
I realise this questions has been asked before but after carefully reading through I can't find the correct answer. I realise this is quite basic but any help would be really appreciated!
python -m pip list answers in terms of Python 2.x
If you're using Python 3.x, you need to do pip3 install flask
Module Flask is installed for Python 2 (Python), but not for Python 3 (Python3) that you are using.
So, install it as pip3 install Flask
Related
So I've been following along a course which deals with web services and I've encountered an issue with flask dependencies.
my requirements.txt looks like this:
PyMySQL==1.0.2
cryptography==37.0.4
Flask==2.2.2
flask_sqlalchemy==2.5.1
sqlalchemy < 1.4.0
flask_migrate==2.7.0
flask_script==2.0.6
sqlalchemy_utils==0.38.3
And my manage.py which I run with python manage.py db init
looks like this
from flask import Flask
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from configuration import Configuration
from models import database
from sqlalchemy_utils import database_exists, create_database
application = Flask(__name__)
application.config.from_object(Configuration)
migrate = Migrate(application, database)
manager = Manager(application)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
if(not database_exists(Configuration.SQLALCHEMY_DATABASE_URI)):
create_database(Configuration.SQLALCHEMY_DATABASE_URI)
manager.run()
When I use flask 2.2.2 I get this error:
Traceback (most recent call last):
File "/home/remax/PycharmProjects/V3/manage.py", line 3, in <module>
from flask_script import Manager
File "/home/remax/PycharmProjects/V3/venv/lib/python3.10/site-packages/flask_script/__init__.py", line 15, in <module>
from flask._compat import text_type
ModuleNotFoundError: No module named 'flask._compat'
But when I go back to flask 1.1.2 I get this
ImportError: cannot import name 'escape' from 'jinja2'
I honestly don't know how to deal with this, I've been trying to find a solution all morning
flask-script has been obsolete since Flask 0.11 added command support. It hasn't been updated to work with Flask 2, so if you want to use Flask 2, you'll need to get rid of it (and use Flask's native command support instead).
If you have upgraded Flask to 2.x and decide to downgrade to 1.x, you will need to install compatible versions of supporting packages (werkzeug, itsdangerous, jinja2). It might be easiest to just uninstall all packages from your virtualenv (you're using one, right?) and reinstall the correct versions, but you can also do it by hand.
This question already has answers here:
Why isn't PyCharm's autocomplete working for libraries I install?
(2 answers)
Closed last year.
I'm new on python, and use 3.10.2 version. I wrote this in vs code;
from flask import Flask
app=Flask(__name__)
if __name__ == "__main__":
app.run(debug=True)
but the result is;
Traceback (most recent call last):
File "blog.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
I tried everything that written on this site but the result is the same. I am using mac and waiting for your help. Thanks.
Try to install the Flask first, use pip.
pip install Flask
reference :
https://flask.palletsprojects.com/en/2.0.x/installation/
I am new to python and I am following "Learn Python the Hard Way" by Zed Shaw. In chapter 50, he asks you to download the lpthw.web framework and run the following the program I listed on the bottom. However, when I try to do so, I get the following error. The book recommended using Python 2 but I decided to try Python 3. I am on a windows 7 computer. If the problem is that I am using Python 3, is there a way to make that framework Python 3 friendly or which other one is recommended for someone learning. Thank you very much for the help.
Error:
Traceback (most recent call last):
File "app.py", line 1, in <module>
import web
File "C:\Python33\lib\site-packages\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
ImportError: No module named 'utils'
Program:
import web
urls = (
'/', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self):
greeting = "Hello World"
return greeting
if __name__ == "__main__":
app.run()
pip install utils would solve your problem :)
I am using the Python web.py framework to design a small web application.
As indicated in the tutorial, when working with authorization I tried the following in the
Python interpreter:
In [10]: import web
In [11]: from web.contrib.auth import DBAuth
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/local/user/python_webcode/<ipython console> in <module>()
ImportError: No module named auth
But I am getting the above error. Can anyone please let me know how to solve this error and explain why it is happening?
It looks like you do not have the auth module installed. I have assumed that the auth module you are trying to use the one at http://jpscaletti.com/webpy_auth/.
You've not indicated whether you installed web.py via easy_install or by running setup.py after downloading a tarball. In either case, I'd recommend that you:
Locate the web.py install folder
Download the auth module from the link above and extract the contents into the contrib/ folder of the web.py install folder
I'm trying to run the hello world tutorial for the Google app engine in Go language. The GAE SDK for go is based on python 2.5, which I installed. I then had to install openssl, but now when I try to run my sample application on the SDK, I get the following error:
ImportError: No module named _md5
I even tried a simple import md5 & import hashlib from the python interpreter interface, and i still get the same error
>>> import hashlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/hashlib.py", line 133, in <module>
md5 = __get_builtin_constructor('md5')
File "/usr/local/lib/python2.5/hashlib.py", line 60, in __get_builtin_constructor
import _md5
ImportError: No module named _md5
Does anybody know a workaround for this? Thank you!
I have a feeling that this problem is really about python installation than anything else
Your problem has nothing to do with GAE, or the SDK. I have faced this before. If you tried to install your custom version of python (on Ubuntu), then you land up with such issues. You should uninstall the custom python using checkinstall. More details can be found about there here: Uninstall python built from source?.
Just use the default python and you'll be fine!