Forum Archive

Flask syntax error (possible installation issue)

victordomingos

I want to try some stuff in flask, and I am stuck right at the beginning.

I typed this in a new file:

from flask import Flask

app = Flask(__name__)

And I get this error (running as python 3.5). If I try to run it as legacy python it does not raise this syntax error.

Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/5E22383E-122A-4BBE-9677-E4A0EF63E7C3/Pythonista3/Documents/flask-experiências/app.py", line 1, in <module>
    from flask import Flask
  File "/private/var/mobile/Containers/Shared/AppGroup/5E22383E-122A-4BBE-9677-E4A0EF63E7C3/Pythonista3/Documents/site-packages/flask/__init__.py", line 21, in <module>
    from .app import Flask, Request, Response
  File "/private/var/mobile/Containers/Shared/AppGroup/5E22383E-122A-4BBE-9677-E4A0EF63E7C3/Pythonista3/Documents/site-packages/flask/app.py", line 1264
    raise exc_type, exc_value, tb
                  ^
SyntaxError: invalid syntax

I am afraid I could have messed system packages while installing modules... Not sure if I tryed to pip install flask.

Any ideas?

JonB

when you use stash pip to install modules, it installes the 2.7 version. pythonista comes with flask installed, so just delete that folder from site packages,

dgelessus

After you delete the flask folder from your site-packages, you might need to restart Pythonista to make the import work again. Python caches imported modules internally, so sometimes you need to fully restart Python to clear old modules from the cache.

victordomingos

@JonB I only work with Python 3. Is there a way to install new modules into Python 3?

Also, is the bundled version of Flask compatible with Python 3?

JonB

The version you have installed is version 0.7 or earlier. Pythonista comes installed with version 0.10.1. Current version is 0.12.x.

The pythonista version is compatible with py3 ( as are current versions), so if you delete the version in site packages, you should be good to go with 0.10.

If you need 0.12, pip install should work, but often requires some manual intervention. In this case, you just need to manually install the missing click dependency:

pip install flask
pip install click

In other cases, with complex setup.py, you can pip download, then tar -xvzf then figure out what needs to be copied.

victordomingos

Ok. Thanks. I have deleted that folder and it seems to work now.