Forums

Not able to run flask app.ImportError: No module named flask

I setup virutalenv in home directory and mentioned the same in web tab. I can my app from console. but not through wsgi

Here is traceback

2016-03-26 15:13:04,391 :Traceback (most recent call last):
2016-03-26 15:13:04,391 :  File "/bin/user_wsgi_wrapper.py", line 138, in __call__
2016-03-26 15:13:04,392 :    self.error_log_file.logger.exception("Error running WSGI application")
2016-03-26 15:13:04,392 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2016-03-26 15:13:04,392 :    self.error(msg, *args, **kwargs)
2016-03-26 15:13:04,392 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2016-03-26 15:13:04,392 :    self._log(ERROR, msg, args, **kwargs)
2016-03-26 15:13:04,392 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2016-03-26 15:13:04,393 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2016-03-26 15:13:04,393 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2016-03-26 15:13:04,393 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2016-03-26 15:13:04,393 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2016-03-26 15:13:04,393 :    self.threadName = threading.current_thread().name
2016-03-26 15:13:04,393 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2016-03-26 15:13:04,394 :    return _active[_get_ident()]
2016-03-26 15:13:04,394 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2016-03-26 15:13:04,394 :    app_iterator = self.app(environ, start_response)
2016-03-26 15:13:04,394 :  File "/bin/user_wsgi_wrapper.py", line 144, in import_error_application
2016-03-26 15:13:04,394 :    raise e
2016-03-26 15:13:04,394 :ImportError: No module named flask

[edit by admin: formatting]

from the console, were you "running" your app within your virtualenv?

if not, you may have just seen your webapp work with our pre-installed flask.

if you are using your own virtualenv, make sure you install flask into it.

Yes,from console I started app in virtualenv only.

today when I tried to start app from console following error occured

Traceback (most recent call last):
  File "run.py", line 5, in <module>
    app.run(host= '0.0.0.0')
  File "/home/neerdshukla/.local/lib/python2.7/site-packages/flask/app.py", line 772, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 613, in run_simple
    test_socket.bind((hostname, port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

[edit by admin: formatting]

thats not running from the virtualenv. its using a user local version of flask as you can see from the stacktrace.

also just to clarify, you can't run webapps from the console- it will run but we will never route any requests to it. so nobody will ever be able to access it

make sure you are in your virtualenv and that you pip install into the virtualenv.

I started in console virtualenv and ran command "pip freeze --user" and got following output

(lared) 08:43 ~/lared$ pip freeze --user
-f /usr/share/pip-wheels
Flask==0.10.1
itsdangerous==0.24
passlib==1.6.5
poster==0.8.1
pydns==2.3.6
pymongo==3.2
redis==2.10.5
Unirest==1.1.7
validate-email==1.3

Output indiicates that flask is installed in virtualenv

For testing setup onlny I run app from console.

[edit by admin: formatting]

That's not showing what's installed in the virtualenv, the --user flag means that it's showing what's installed locally for your username (which is ignored when you're in the virtualenv).

For clarity: there are two options to install packages:

  • pip install --user, which installs things in the .local subdirectory of your home directory.
  • using a virtualenv, when you either use workon to enter the virtualenv, or you start a bash console inside the virtualenv from the "Web" tab. In this case, you should use pip install without the --user flag.

So, if from a bash console inside your virtualenv you run pip freeze with no --user flag, then you'll see what's in the virtualenv. I suspect that Flask won't be there, so you'll need to run pip install Flask==0.10.1 to install it.

I ran "pip install" got following output

(lared) 16:39 ~/lared$ pip freeze
-f /usr/share/pip-wheels
aggdraw==1.1.post20051010
alabaster==0.7.7
alembic==0.6.2
aniso8601==0.92
ansible==1.5.4
argh==0.26.1
async==0.6.1
Augustus==0.5.3.0
Babel==0.9.6
backports-abc==0.4
backports.ssl-match-hostname==3.5.0.1
basemap==1.0.7
bashplotlib==0.4.4
beanstalkc==0.3.0
BeautifulSoup==3.2.1
beautifulsoup4==4.2.1
biopython==1.61
bleach==1.2.2
blessings==1.6
blinker==1.2
boto==2.3.0
bottle==0.11.6
bottlenose==0.6.2
bpython==0.14.2
BTrees==4.0.8
bzr==2.6.0
cairocffi==0.5.3
CairoSVG==1.0.6
census==0.6
certifi==2016.2.28
cffi==1.5.0
Chameleon==2.11
chardet==2.2.1
Cheetah==2.4.4
CherryPy==3.2.4
colorama==0.3.7
configobj==4.7.2
CoolProp==5.0.3
coverage==3.6
cssselect==0.8
curtsies==0.1.23
cvxopt==1.1.6
cypari==1.2.2
Cython==0.23.4
dataset==0.4.0
decorator==3.4.0
Django==1.3.7
django-blog-zinnia==0.12.3
django-bootstrap-form==3.1
django-classy-tags==0.4
django-cms==2.4.2
django-mptt==0.5.5
django-openid-auth==0.5
django-registration==0.8
django-sekizai==0.7
django-social-auth==0.7.23
django-tagging==0.3.1
django-xmlrpc==0.1.5
django4facebook==0.1.0
docopt==0.6.1
docutils==0.10
dropbox==1.5.1
dulwich==0.9.4
easydev==0.9.14
EasyProcess==0.1.6
epydoc==3.0.1
evernote==1.25.1
Fabric==1.6.1
facebook-sdk==0.4.0
falcon==0.1.10
feedgenerator==1.6
feedparser==5.1.3
filebrowser-safe==0.2.27
Fiona==0.15
Flask==0.10.1
Flask-Admin==1.0.9
Flask-Babel==0.8
Flask-Bcrypt==0.6.0
Flask-Bootstrap==3.1.1.2
Flask-HTTPAuth==2.2.0
Flask-Login==0.1.3
Flask-Mail==0.8.2
Flask-OpenID==1.1.1
Flask-RESTful==0.3.1
Flask-Script==0.5.3
Flask-SQLAlchemy==0.16
Flask-WhooshAlchemy==0.55a0
Flask-WTF==0.8.3
funcsigs==0.4
functools32==3.2.3.post2
futures==2.1.3
FXrays==1.3.1
GDAL==1.9.1
gdata==2.0.17
Genshi==0.7
gensim==0.10.0
GeoIP==1.2.9
geopy==0.95.1
gevent==1.0.1
geventhttpclient==1.0a0
gitdb==0.5.4
GitPython==0.3.2rc1
gmpy==1.16
google-api-python-client==1.1
grappelli-safe==0.2.21
greenlet==0.4.1
grequests==0.2.0
grok==1.11.3
grokcore.annotation==1.3
grokcore.catalog==2.0
grokcore.chameleon==1.0.3
grokcore.component==2.5
grokcore.content==1.1
grokcore.formlib==1.9
grokcore.json==1.2
grokcore.layout==1.6
grokcore.message==0.4.2
grokcore.rest==1.3
grokcore.security==1.6.2
grokcore.site==1.6.1
grokcore.traverser==1.2
grokcore.view==2.8
grokcore.viewlet==1.11
grokcore.xmlrpc==1.2
hg-git==0.4.0
html5lib==0.95
http-parser==0.8.1
httplib2==0.8
IMAPClient==0.10.2
incf.countryutils==1.0
iotop==0.6
ipykernel==4.3.1
ipyparallel==5.0.1
ipython==4.1.2
ipython-genutils==0.1.0
ipywidgets==4.1.1
isodate==0.4.9
itsdangerous==0.24
jellyfish==0.2.0
Jinja2==2.7
jsonschema==2.5.1
jupyter==1.0.0
jupyter-client==4.2.1
jupyter-console==4.1.1
jupyter-core==4.1.0
la==0.6.0
Logbook==0.8.1
lxml==3.3.5
Mako==0.8.1
marisa-trie==0.5.1
Markdown==2.3.1
MarkupSafe==0.18
martian==0.14
matplotlib==1.4.3
mechanize==0.2.5
mercurial==2.6.3
Mezzanine==1.4.3
mistune==0.7.2
mlpy==3.5.0
mock==1.0.1
mod-pywebsocket==0.6b1
moin==1.9.7
mplh5canvas==0.7
mpmath==0.17
mysql-connector-python==1.0.12
MySQL-python==1.2.5
nbconvert==4.1.0
nbformat==4.0.1
ndg-httpsclient==0.4.0
netCDF4==1.1.1
netifaces==0.8
networkx==1.7
nltk==3.0.0
nose==1.3.0
notebook==4.1.0
numexpr==2.4
numpy==1.8.1
oauth==1.0.1
oauth2==1.5.211
oauthlib==1.0.3
openopt==0.5402
openpyxl==1.6.2
Orange==2.7.8
Orange-Text==1.2a1
ordereddict==1.1
oursql==0.9.3.1
pandas==0.14.1
paramiko==1.10.1
passlib==1.6.5
Paste==1.7.5.1
PasteDeploy==1.5.0
path.py==8.1.2
pathtools==0.1.2
patsy==0.2.1
Pattern==2.6
pbr==0.11.1
pdflatex==0.1.0
pdfminer==20110515
peewee==2.1.2
pelican==3.5.0
pep8==1.4.5
persistent==4.0.6
pexpect==2.4
pickleshare==0.6
PIL==1.1.7
Pillow==3.1.1
Pinax==0.9a2
pisa==3.0.33
Pivy==0.5.0
plink==1.8
plotly==1.9.3
poster==0.8.1
pp==1.6.4
prettytable==0.6.1
psutil==1.2.1
psycopg2==2.5
ptyprocess==0.5.1
pudb==2013.3.2
py-bcrypt==0.4
PyAMF==0.6.1
pyasn1==0.1.7
PyChart==1.39
pycparser==2.14
pycrypto==2.6
pycsp==0.9.0
pycurl==7.19.0
pyDatalog==0.13.0
pydns==2.3.6
pydot==1.0.28
pydub==0.9.5
pyenchant==1.6.6
pyfits==3.1.2
pyflakes==0.7.2
pygal==1.2.1
pygeoip==0.3.2
Pygments==1.6
pygraphviz==1.1
pyhdf==0.8.3
Pykka==1.1.0
pymc==2.3.2
pymongo==3.2
pyOpenSSL==0.13
pyparsing==1.5.7
PyPDF2==1.25.1
pypdfocr==0.7.4
Pyphen==0.9.1
pypng==0.0.18
pyproj==1.9.3
pyquery==1.2.4
pyramid==1.4.2
PySAL==1.5.0
pyserial==2.6
pyspotify==1.11
PyStemmer==1.3.0
pytesseract==0.1.5
python-amazon-simple-product-api==1.5.0
python-dateutil==2.2
python-gflags==2.0
python-inotify==0.5
python-instagram==0.8.0
python-ldap==2.4.13
python-Levenshtein==0.10.2
python-magic==0.4.3
python-mcrypt==1.1
python-mhash==1.4
python-mimeparse==0.1.4
python-openid==2.2.5
python-slugify==0.0.7
pytz==2015.7
PyVirtualDisplay==0.1.2
PyYAML==3.11
pyzmq==13.1.0
qrcode==2.7
qtconsole==4.2.0
Quandl==2.2
quantlib==0.1
QuantLib-Python==1.3
rdflib==4.0.1
redis==2.10.5
remix==2.1.3
reportlab==2.7
repoze.lru==0.6
requests==2.2.0
requests-cache==0.4.4
requests-oauthlib==0.6.1
resolver-test==1.0.1
restkit==4.2.1
RestrictedPython==3.6.0
rpy2==2.5.2
ruffus==2.5
s3cmd==1.1.0b3
scikit-learn==0.14.1
scikits.statsmodels==0.3.1
scipy==0.14.0
Scrapy==0.16.5
selenium==2.33.0
setproctitle==1.1.7
Shapely==1.3.1
simplegeneric==0.8.1
SimpleHMMER==0.2.3
simplejson==3.3.0
simpy==3.0.5
singledispatch==3.4.0.3
six==1.8.0
smmap==0.8.2
snappy==2.3.2
snowballstemmer==1.2.1
soaplib==2.0.0b2
socketpool==0.5.2
sockjs-tornado==1.0.0
South==0.8.1
SPARQLWrapper==1.5.2
speaklater==1.3
spectrum==0.5.6
spherogram==1.4.1
Sphinx==1.3.1
sphinx-rtd-theme==0.1.9
splinter==0.5.2
SQLAlchemy==0.8.3
sqlalchemy-migrate==0.8.2
statsmodels==0.5.0
stevedore==0.9.1
stripe==1.12.0
suds==0.4
svn==0.3.24
sympy==0.7.2
TA-Lib==0.4.8
tables==3.1.1
tabulate==0.7.5
Tempita==0.5.1
terminado==0.6
TesseractTrainer==0.1.1
texcaller==0
textblob==0.8.4
tinycss==0.3
TornadIO2==0.0.3
tornado==3.0.2
Trac==1.0.1
traitlets==4.1.0
transaction==1.4.1
translationstring==1.1
tweepy==3.5.0
twilio==3.6.13
Twisted==13.0.0
twitter==1.14.3
Unidecode==0.4.13
Unirest==1.1.7
unittest2==0.5.1
urllib3==1.5
urwid==1.1.1
us==0.7
validate-email==1.3
venusian==1.0a8
virtualenv==15.0.0
virtualenv-clone==0.2.6
virtualenvwrapper==4.7.1
VTK==5.8.0
w3lib==1.3
Wand==0.3.8
watchdog==0.8.3
WeasyPrint==0.22
web.py==0.37
webapp2==2.5.2
WebOb==1.2.3
Werkzeug==0.8.3
wheezy.caching==0.1.112
wheezy.core==0.1.136
wheezy.html==0.1.145
wheezy.http==0.1.332
wheezy.routing==0.1.153
wheezy.security==0.1.61
wheezy.template==0.1.155
wheezy.validation==0.1.130
wheezy.web==0.1.450
Whoosh==2.4.1
WTForms==1.0.4
wxPython==2.8.12.1
wxPython-common==2.8.12.1
xlrd==0.9.2
xlutils==1.6.0
xlwt==0.7.5
z3c.autoinclude==0.3.4
z3c.flashmessage==1.3
z3c.pt==3.0.0a1
zbar==0.10
zc.buildout==2.1.0
zc.catalog==1.5.1
zc.lockfile==1.1.0
ZConfig==3.0.3
zdaemon==4.0.0
ZEO==4.0.0b1
zipline==0.7.0
ZODB==4.0.0b3
ZODB3==3.11.0a3
zope.annotation==4.2.0
zope.app.appsetup==4.0.0a1
zope.app.publication==4.0.0a1.dev0
zope.app.wsgi==4.0.0a4
zope.authentication==4.1.0
zope.browser==2.0.2
zope.browserpage==4.1.0a1
zope.browserresource==4.0.1
zope.catalog==4.0.0a1
zope.component==4.1.0
zope.configuration==4.0.2
zope.container==4.0.0a3
zope.contentprovider==4.0.0a1
zope.contenttype==4.0.1
zope.datetime==4.0.0
zope.deprecation==4.0.2
zope.dottedname==4.0.1
zope.error==4.1.0
zope.errorview==0.11
zope.event==4.0.2
zope.exceptions==4.0.6
zope.filerepresentation==4.0.2
zope.formlib==4.3.0a1
zope.i18n==4.0.0a4
zope.i18nmessageid==4.0.2
zope.index==4.0.1
zope.interface==4.0.1
zope.intid==4.0.0a1
zope.keyreference==4.0.0a2
zope.lifecycleevent==4.0.2
zope.location==4.0.2
zope.login==2.0.0a1
zope.minmax==2.0.0
zope.pagetemplate==4.0.4
zope.password==4.0.2
zope.principalregistry==4.0.0a2
zope.processlifetime==2.0.0
zope.proxy==4.1.3
zope.ptresource==4.0.0a1
zope.publisher==4.0.0a4
zope.schema==4.3.2
zope.security==4.0.0b1
zope.securitypolicy==4.0.0a1
zope.session==4.0.0a1
zope.site==4.0.0a1
zope.size==4.0.1
zope.tal==4.0.0a1
zope.tales==4.0.1
zope.testing==4.1.2
zope.traversing==4.0.0a3
zope.viewlet==4.0.0a1

Flask is installed here as well.

[edit by admin: formatting]

That's a lot of stuff in your virtualenv. How did you create it?

I removed virutualev directory and recreated and ran pip install -r requirements.txt again. Issue resolved. Thanks for help. Now pip freeze is showing only

(lared) 17:00 ~$ pip freeze
-f /usr/share/pip-wheels
Flask==0.10.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
passlib==1.6.5
pydns==2.3.6
pymongo==3.2
redis==2.10.5
validate-email==1.3
Werkzeug==0.11.5

Issue is resolved. But wanna ask one question. How can I remove these unwanted packages (mentioned in previous post) from local installation ?

If you look in the .local/lib/python2.7/site-packages you'll see the packages that you have installed locally. You can uninstall them one by one by using pip uninstall if you want, but if you're normally using a virtualenv, they won't do any harm.

Please, i want to import my app in ipython3.6 and create tables with my db but it says no module found for my app name

We have a help page that should help you work out what the problem is: http://help.pythonanywhere.com/pages/DebuggingImportError/

thanks, looks like ipython cannot "see" the file in the /mysite folder but when i placed it in the user(intelliapi) folder, it "saw" it