KyleBenson / scale_client

The Python-based SCALE Client software for acquiring data from various sensors (i.e. via Raspberry Pi platform), processing it, and sharing it through multiple networks and data exchange protocols.
http://scale.ics.uci.edu/
Other
4 stars 8 forks source link

Failures with absolute imports #17

Closed bfrggit closed 9 years ago

bfrggit commented 9 years ago

PyCharm resulted in absolute imports after Kyle's re-factory. These absolute imports cannot be resolved by Python 2. As a consequence, the clients no longer work if we attempt to run them like this:

cd /home/pi/SmartAmericaSensors/scale_client/core
./client_computer.py

Setting up environment variables may help solve this problem. We can run the clients with

cd /home/pi/SmartAmericaSensors/scale_client/core
env PYTHONPATH=/home/pi/SmartAmericaSensors ./client_computer.py

However, since our client will be registered as a daemon (also known as a Linux service) and will be called using start-stop-daemon, where environment variables are discarded, the solution above won't work in real deployments.

Tested working:

  1. Having the following code paragraph at the beginning of the client file:
import sys
sys.path.append("/home/pi/SmartAmericaSensors"); # Path hard-coded in script

Tested NOT working:

  1. Having PYTHONPATH set-up in /etc/environment
  2. Having PYTHONPATH set-up in the daemon configuration file (/etc/init.d/scale).
  3. Having env PYTHONPATH=/home/pi/SmartAmericaSensors before start-stop-daemon in the daemon configuration file.
  4. Running the client with Python 3 (python3)

Not tested:

  1. Using from __future__ import absolute_import in scripts
KyleBenson commented 9 years ago

This behavior is now documented in the README and a setup.py file has been added to facilitate installing the scale_client package.