1

I have installed Apache2 on the Raspberry and the idea is to run a Flask app. I managed to write a very simple app:

import requests
from flask import Flask
from flask import make_response
from flask import render_template

app = Flask(__name__)

@app.route("/")
def index():
    url = "http://192.168.0.25/temp"
    temp = requests.get(url).content
    url = "http://192.168.0.25/humidity"
    hum = requests.get(url).content
    response = make_response(render_template("home.html", temp=temp, hum=hum))
    return response

if __name__ == '__main__':
    app.run(port=5001, debug=True)

which works but, as soon as I attempt to import libraries (even very basic ones) troubles begin. Just to give you the general picture there is no virtual environment involved and I have the standard install of Python.

As soon as I add import like:

from datetime import *
from time import *
import json

but this produce an error and Flask does not serve anything.

Thinking that - even if it seemed unlikely - I could miss some of these libraries, I tried to install them manually, e.g.

pip install json

and the same for 'time' and 'datetime', but this does not produce the desired outcome and I get

Could not find a version that satisfies the requirement json (from versions: )
No matching distribution found for json 

I wanted to check if the libraries were there and were accessible to Python so, I wrote a very silly test, like:

from time import *

while True:
    print('test')
    time.sleep(5)

which I run from the CLI, $ python test.py, and it worked as expected.

So the questions are:

  • why are these library inaccessible/I get an error?

  • why the error about the matching distribution?

Pythonic thanks for your help :)

  • 1
    1) "but this produce an error" - What is the error message? 2) "and Flask does not serve anything" - If what you shown is all the code you have, you did not import Flask nor has any code to create an instance of Flask class. 3) are you using python3 or python2? – hcheung Oct 12 '18 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.