Im trying to run a flask app locally with also using the cs50 module but i keep getting an error:

NoAppException: While importing "application", an ImportError was raised: Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/flask/cli.py", line 235, in locate_app import(module_name) File "/home/rasguy92/Documents/CS50 edX/webTrak/flask/register/application.py", line 2, in import cs50 File "/usr/lib/python2.7/site-packages/cs50/init.py", line 17, in from . import flask ImportError: cannot import name flask

I know that this has something to do with the cs50 module because the error occurs in cs50/init.py furthermore, when i don't import the cs50 module everything just works fine, hopefully you guys can help me out

this is my code:

import cs50
from flask import Flask, render_template

# initiate database and app
app = Flask(__name__)
db = cs50.SQL('sqlite:///lecture.db')

def index():
    return "HELLO WORLD"```

1 Answer 1


Do you have the cs50 flask.py in /usr/lib/python2.7/site-packages/cs50/? Notice, it's importing from "this directory" from . import flask.

And beware: the script is running under python 2.7 as per the error message (execute python -V to verify). Make sure you are executing the program with python3 since that's where the CS50 module was installed (as per the comments). python2.7 was end-of-life'd as of Jan 2020.

You probably want to create an alias in your environment to make sure the python command calls python3 ( that's how it is done on the IDE) since this is will be running under flask.

  • yes, but what does the . mean ? and do i need to change the directory from which it's importing ?
    – rassenguy
    Commented Feb 9, 2020 at 22:03
  • The . means "here", ie from this directory which i would expect to be "/usr/lib/python2.7/site-packages/cs50/" . Check the corresponding directory in the IDE (which is /usr/local/lib/python3.7/site-packages/cs50/). Maybe it's a version problem, since the error message python2.7? This program works in the IDE so it is more than likely some set up issue in the local environment. (python 2.7 reached end-of-life 1 Jan 2020). Commented Feb 9, 2020 at 22:40
  • I forked the cs50/ and i added the contets of it's src foldre to to this folder: ``` /usr/local/lib/python3.7/site-packages/cs50/ but it seems im getting an invalid sintax error: File "/usr/lib/python2.7/site-packages/cs50/sql.py", line 404 return sqlparse.sql.Token(sqlparse.tokens.Other, f"x'{value.hex()}'") # dev.mysql.com/doc/refman/8.0/en/hexadecimal-literals.html ^ SyntaxError: invalid syntax
    – rassenguy
    Commented Feb 9, 2020 at 23:14
  • Still think version is in play. Read the paths in your comment very carefully. Another choice is to use pythons sqlite3 library instead of cs50. Commented Feb 9, 2020 at 23:23
  • ok i will try the other library, but i just cant keep wondering if there exists a way to still use the cs50 library
    – rassenguy
    Commented Feb 9, 2020 at 23:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .