I'm learning a little bit how function python, more specific Flask.
I'm creating a new project using flask, but when I create a new file and import Flask I receive this error: No name 'Flask' in module 'flask'pylint(no-name-in-module)
I did read that, I need create a file called: __init__.py but I have this and the error keeps showing up.
This is my actual code (very simple code, and folder/files structure):
Thanks for the help! :D
I tried this: Flask ImportError: No Module Named Flask, but this solution does not works for me.
I installed flask on python 2.7 and run simple hello world script and it worked fine. Then I updated python to python 3.8 and I got an error similar to yours:
Unable to import 'flask'pylint(import-error)
I simply uninstalled flask and installed again and it worked for me. Run this two commands:
pip uninstall flask
pip install flask
Then export the FLASK_APP environment variable and run flask
set FLASK_APP=file.py
flask run
I solved this changing my python interpreter. I did uninstall pylint and install pylama and now all is fine!
Related
I've been using this tutorial to setup flask on ubuntu server.
It worked fine for one project, now I try to setup it on the other one.
This time the app works fine without SQLAlchemy, but once I use it, it gives 'Internal server error'.
checked the installation of flask_sqlalchemy - looks fine
made sure I don't have a file named 'sqlalchemy'
I can launch the app with sqlalchemy but without virtualenv, it works fine!
I double-checked that flask_sqlalchemy has the same configuration in virtualenv library, as in the python library
error that I receive:
Traceback (most recent call last):
File "myproject2.py", line 4, in <module>
from flask_sqlalchemy import SQLAlchemy
File "/root/myproject2/myprojectenv2/lib/python3.8/site-packages/flask_sqlalch emy/__init__.py", line 16, in <module>
from sqlalchemy import event, inspect, orm
ImportError: cannot import name 'inspect' from 'sqlalchemy' (/root/myproject2/my projectenv2/lib/python3.8/site-packages/sqlalchemy/__init__.py)
Thank you for any suggestions!
It seems your installation is broken in the virtualenv. Try reinstalling by running this from within the virtualenv:
pip install --upgrade --force-reinstall flask-sqlalchemy sqlalchemy
I have run into same problem but with different kind of issue. While upgrading to recent flask_sqlalchemy and sqlalchemy libraries, I have noticed that construct has been changed from:
from flask_sqlalchemy import inspect
this got broken, and new construct is:
from sqlalchemy import inspect
just want to state something that may be easily overseen
apart from that the issue may be wrong libraries in venv on specific installations
I have system python 3.10 however I run app under python 3.7 for compatibility reasons. On that line, I have noticed that it is easy to mix python library versions and get 3.10 library under 3.7 venv - pay attention during installation of SQL libraries - pip may go wild.
hope these hints help someone as these issues drove me nuts for days
I have only python 3.8.5 installed.
I started diving into Python and Flask for the first time (I'm coming from the javascript side of things). I've already ran into an interesting issue in just my first few lines of code.
I was able to run pipenv install flask flask-sqlalchemy flask-marshmallow marshmallow-sqlalchemy and they all seemed to have installed just fine. They all appear in the pipfile.lock. flask-marshmallow is version 0.13.0.
pipfile.lock
When I started coding, I was able to import flask and flask_sqlalchemy with no issues. Intellisense even helped me out with them. But from flask-marshmallow import Marshmallow didn't seem to work.
When I ran python app.py I get the following error
Traceback (most recent call last):
File "app.py", line 3, in <module>
from flask_marshmallow import Marshmallow
ModuleNotFoundError: No module named 'flask_marshmallow'
I've tried uninstalling flask-marshmallow and marshmallow and reinstalling. The console always says the installation is successful but I can't seem to import it when all the other packages seem to work fine.
What a great start to a new language xD Here is the whole file so far for reference, if I remove the marshmallow line it starts without any issues
from flask import Flask, request, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
import os
app = Flask(__name__)
if __name__ == "__main__":
app.run(debug=True)
Make sure that, because you have created a pipenv, you have set the Python interpreter path correctly in your IDE.
I was facing the exact issue (and that is how I reached this question). I am using VS code, was using python3.8 and pipenv.
Even though I have installed the packages using pip3, I was facing import issues while running the code. After a futile search on the Internet, I realised that the issue was very silly.
The Python interpreter path (Cntrl+Shift+P -> Select Interpreter) was not set to the newly created pipenv. After I have set the interpreter path properly, the code resumed to function as expected.
i would suggest to check the site packages file and make sure that it is installed in it if not then it is installed in other directory
Also try working it in another normal python file and check if that works too
Check syntax also i know i know its obvious but just saying
In my case I was trying to run the command flask db init, and it would give the error above. I got it to work by running the command with sudo privileges sudo flask db init. I hope this can help someone else out in a similar situation!
I'm more or less new to computer science and can not even manage to run my first "Hello World" in Flask (Python 3; on my Windows-10 computer). I have tried some different tutorials on how to get started with Flask but did not find them really helpful so I did not finish them. Eventually I found a tutorial that seemed comprehensive and fitting my needs, but Visual Studio Code Terminal could not execute my code but gave me back an Error Message. Maybe I created a global virtual environment before I started this course that I'm following along now, and that's why it gives me that Error, but am not sure.
So this is the tutorial that I eventually picked and am currently following along: https://www.youtube.com/watch?v=QjtW-wnXlUY.
The tutorial showed me how to set up and activate a local virtual environment in my project folder and pip install Flask as well as save app.py, with the help of my command batch and VSCode.
Then the user should try and run the following code (see below this paragraph). On my browser it really worked perfectly fine, but the Visual Studio Code-Terminal gave me an error message called "ModuleNotFoundError: No module named 'flask'" (I know there are some similar-named threads out there in stackoverflow, but the answers given did not help me with my problem and also it seems to me that my case is slightly different). So this is the code I tried to run in Visual Studio Code:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def index():
return "Hello world!"
And this is the complete ErrorMessage that Visual Studio Code-Terminal gave me:
PS C:\Program Files\DB Browser for SQLite> & C:/Users/User/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/User/Desktop/Flask_app/app.py
Traceback (most recent call last):
File "c:/Users/User/Desktop/Flask_app/app.py", line 1, in <module>
from flask import Flask
**ModuleNotFoundError: No module named 'flask'**
PS C:\Program Files\DB Browser for SQLite>
Any ideas what's wrong with my code? Maybe it has to do with the path I stored it in? I got no idea; am very thankful for help!
Cheers.
Make sure the virtual environment you created is activated before running the app.
Also make sure it is activated when you run 'pip install flask'.
first install the flask in your system
pip install flask
run the flask server then try it
> set FLASK_APP=hello
> flask run
I'm trying to install the vimpdb lib but it's working, even though I successfully installed vimpdb using pip install I always get this error:
import vimpdb; vimpdb.set_trace();
ImportError: No module named vimpdb
I'm running the code locally but when I run the same code as a simple script (without using localhost) it imports correctly, it only throws an error when I start a server and begin to try using this plugin.
Any ideas?
Thansk!
App Engine won't import Python modules on your Python path. You need to actually include the module within the App Engine project.
For example, in the same directory as app.yaml, you could add a symbolic link similar to this:
vimpdb -> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/vimpdb
Or you could copy the vimpdb directory to that location.
I have the following code :
#!/usr/bin/env python2
#coding: utf-8
from flask import Flask, render_template
from flask.ext.flatpages import FlatPages
from flask.ext.markdown import Markdown
But when I try to run it, this error occurs : ImportError: No module named flask.ext.markdown whereas normally this module is existing.
Is there somebody who can say how to fix that ?
It seems you need to install the flask-markdown plugin.
http://pythonhosted.org/Flask-Markdown/
You can install this with pip:
pip install flask-markdown
alternatively:
easy_install flask-markdown
If it is already installed try downloading the source and importing it directly.
That module hasn't been updated in over 3 years and uses the old flask extension API. There is a newer package called flask-markdown2.