Closed walchko closed 6 years ago
ok, so installing flask
fixed nothing.
pi@terra examples $ pip install flask
Collecting flask
Downloading Flask-0.12.2-py2.py3-none-any.whl (83kB)
100% |████████████████████████████████| 92kB 159kB/s
Collecting click>=2.0 (from flask)
Downloading click-6.7-py2.py3-none-any.whl (71kB)
100% |████████████████████████████████| 71kB 456kB/s
Collecting Jinja2>=2.4 (from flask)
Downloading Jinja2-2.10-py2.py3-none-any.whl (126kB)
100% |████████████████████████████████| 133kB 513kB/s
Collecting itsdangerous>=0.21 (from flask)
Downloading itsdangerous-0.24.tar.gz (46kB)
100% |████████████████████████████████| 51kB 579kB/s
Collecting Werkzeug>=0.7 (from flask)
Downloading Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
100% |████████████████████████████████| 327kB 241kB/s
Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->flask)
Downloading MarkupSafe-1.0.tar.gz
Building wheels for collected packages: itsdangerous, MarkupSafe
Running setup.py bdist_wheel for itsdangerous ... done
Stored in directory: /home/pi/.cache/pip/wheels/fc/a8/66/24d655233c757e178d45dea2de22a04c6d92766abfb741129a
Running setup.py bdist_wheel for MarkupSafe ... done
Stored in directory: /home/pi/.cache/pip/wheels/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57
Successfully built itsdangerous MarkupSafe
Installing collected packages: click, MarkupSafe, Jinja2, itsdangerous, Werkzeug, flask
Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-0.12.2 itsdangerous-0.24
Now running it:
pi@terra examples $ ./hello-world.py
Traceback (most recent call last):
File "./hello-world.py", line 6, in <module>
import scrollphathd
File "/usr/local/lib/python2.7/dist-packages/scrollphathd/__init__.py", line 2, in <module>
from .api.http import start_background_thread, scrollphathd_blueprint
File "/usr/local/lib/python2.7/dist-packages/scrollphathd/api/http.py", line 21, in <module>
raise ImportError("flask must be installed in order to use the api. Install with pip install flask")
ImportError: flask must be installed in order to use the api. Install with pip install flask
This should probably be switched to a soft dependency- disabling the API when it's not available and emitting a warning.
Numpy should not need compiled on the Pi, it should be available both as a binary .whl file and as a deb package: sudo apt install python-numpy
.
Since Flask still seems to be raising an import error, what do you get when you:
python
>>> from flask import Blueprint, render_template, abort, request, jsonify, Flask
I've removed the unnecessary import of the Flask Blueprint from __init__.py
, which means you have to explicitly import scrollphathd.api.http
in order to run into a Flask dependency.
I suspect the well-meaning try / except
around the Flask import is producing a side-effect where they actual content of the error is lost. IE: if I were running Flask 0.6.1 (a very old version, but for the sake of argument) and imported with the try / except
in place, it would produce:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/pi/Development/scroll-phat-hd-master/library/scrollphathd/api/http.py", line 21, in <module>
raise ImportError("flask must be installed in order to use the api. Install with pip install flask")
ImportError: flask must be installed in order to use the api. Install with pip install flask.
Whereas removing the attempt to be helpful results in:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/pi/Development/scroll-phat-hd-master/library/scrollphathd/api/http.py", line 19, in <module>
from flask import Blueprint, render_template, abort, request, jsonify, Flask
ImportError: cannot import name Blueprint
The latter has the specific line of code that went awry, and the specific error. This context and information was previously being lost :(
So, I like to use pip
to keep my python libraries updated. The debian packages are often outdated. However, for the Pi Zero, maybe because it is ARM6, it needs to be compiled ... I watched it happen and it took a while.
Maybe if you load a fresh version of raspbian onto a Pi Zero and do pip install -U numpy
, you will see what I mean. Again, yes you can use an older version with sudo apt-get python-numpy
.
I have already forked and removed flask
code from your driver. I may also look into removing numpy
since it really isn't needed. You just do a couple simple matrix re-orders. Thanks for your response and have a great day! :smile:
It's possible something's gone awry, but as I understand it, it should now by default pull the numpy *.whl from here: https://www.piwheels.hostedpi.com/simple/numpy/
Since https://github.com/bennuttall/piwheels says:
Raspbian Stretch includes configuration for pip to use piwheels by default.
The version at time of writing is 1.14.1 then that would mean either numpy-1.14.1-cp34-cp34m-linux_armv6l.whl
or numpy-1.14.1-cp35-cp35m-linux_armv6l.whl
should be pulled instead of the source package.
Are you running a Jessie or Stretch image?
raspbian stretch
I am running a fresh install of stretch on a RPi Zero, and this issue arises as I try to run the examples. This issue is closed, but I did not understand what the actual solution was?
oh, you have to install Flask and build numpy (which takes a while). It really isn't a problem that breaks anything, but just a lot of time to build numpy and install a bunch of stuff I personally didn't think should be in hardware drive code.
I installed Flask only, and it started working. So there was no need to build numpy.
The pimoroni scripts have so far been installing all the dependencies (and I have quite a few HATs and pHATs), this was the first time, that a dependency was not pulled in by them.
And I agree that all this API stuff should be separate from the code that drives the hardware.
I have the same error.
So your setup file only calls out
numpy
but you have a file buried in your library (api/http.py
) that requiresflask
to be installed. Suggest, you move it out to the examples. It seems silly to have a large requirement likeflask
for an lcd matrix.When I tried to run
hello-world.py
it complained aboutflask
even though I am not doing any http/internet stuff.I would also argue for
numpy
to be removed since it takes forever fornumpy
to compile on a Pi Zero, but ...