Flask/Ubuntu 12.04 LTS

Z Wikiverzity
Skočit na navigaci Skočit na vyhledávání

Instalace Flask na Ubuntu 12.04 LTS

# pip3 install Flask

Instaluje také závislosti Werkzeug a Jinja 2 aj., během instalace často hlásí chybu syntaxe:

Downloading/unpacking Flask
  Downloading Flask-0.10.1.tar.gz (544kB): 544kB downloaded
  Running setup.py (path:/tmp/pip_build_root/Flask/setup.py) egg_info for package Flask

...

Downloading/unpacking Jinja2>=2.4 (from Flask)
  Downloading Jinja2-2.7.3.tar.gz (378kB): 378kB downloaded
  Running setup.py (path:/tmp/pip_build_root/Jinja2/setup.py) egg_info for package Jinja2

...
  
Downloading/unpacking itsdangerous>=0.21 (from Flask)
  Downloading itsdangerous-0.24.tar.gz (46kB): 46kB downloaded
  Running setup.py (path:/tmp/pip_build_root/itsdangerous/setup.py) egg_info for package itsdangerous

...

Downloading/unpacking markupsafe (from Jinja2>=2.4->Flask)
  Downloading MarkupSafe-0.23.tar.gz
  Running setup.py (path:/tmp/pip_build_root/markupsafe/setup.py) egg_info for package markupsafe
 
...

Installing collected packages: Flask, Werkzeug, Jinja2, itsdangerous, markupsafe
  Running setup.py install for Flask
    

      File "/usr/local/lib/python3.2/dist-packages/flask/json.py", line 187
        .replace(u'<', u'\\u003c') \
                    ^
    SyntaxError: invalid syntax
    
      File "/usr/local/lib/python3.2/dist-packages/flask/testsuite/appctx.py", line 92
        return u''
                 ^
    SyntaxError: invalid syntax

...atd.
     File "/usr/local/lib/python3.2/dist-packages/werkzeug/datastructures.py", line 1101
        if u'\n' in value or u'\r' in value:
               ^
    SyntaxError: invalid syntax
    
      File "/usr/local/lib/python3.2/dist-packages/werkzeug/wsgi.py", line 376
        parts = netloc.split(u'@', 1)[-1].split(u':', 1)
                                ^
    SyntaxError: invalid syntax
    
      File "/usr/local/lib/python3.2/dist-packages/werkzeug/wrappers.py", line 542
        return self.path + u'?' + to_unicode(self.query_string, self.url_charset)
                              ^
    SyntaxError: invalid syntax

...
    ==========================================================================
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Plain-Python installation succeeded.
    ==========================================================================
Successfully installed Flask Werkzeug Jinja2 itsdangerous markupsafe
Cleaning up...

Působí to dojmem, jako že to je pro Python 2 a ne pro Python 3. Dohledáme:

If you want to use Flask with Python 3 you will need to use Python 3.3 or higher. 3.2 and older are not supported. In addition to that you need to use the latest and greatest versions of itsdangerous, Jinja2 and Werkzeug.

Tak to je asi ten problém, protože na Ubuntu 12.04 LTS je Python 3.2.3 (default, Feb 27 2014, 21:33:50)

Jinak během instalace to včechno sežralo asi 10 MB na disku.

Řešením je nainstalovat si vyšší verzi Pythonu, viz např: