kizniche / Mycodo

An environmental monitoring and regulation system
http://kylegabriel.com/projects/
GNU General Public License v3.0
2.89k stars 488 forks source link

Which env to test mycodo scripts from the command line? #1311

Closed lalebarde closed 1 year ago

lalebarde commented 1 year ago

THIS IS A SELF ANSWER TICKET YOU CAN CLOSE I RECORD IF USEFUL FOR OTHERS

I would like to test mycodo controllers from the command line to quick check syntax errors in my python code. I proceed like this:

pi@raspberrypi:~ $ python3 /home/pi/Mycodo/mycodo/user_python_code/conditional_045edd83-4918-4ef5-beda-fa11a3b5c52c.py
Traceback (most recent call last):
  File "/home/pi/Mycodo/mycodo/user_python_code/conditional_045edd83-4918-4ef5-beda-fa11a3b5c52c.py", line 4, in <module>
    from mycodo.controllers.base_conditional import AbstractConditional
  File "/var/mycodo-root/mycodo/controllers/base_conditional.py", line 13, in <module>
    from mycodo.config import MYCODO_DB_PATH
  File "/var/mycodo-root/mycodo/config.py", line 10, in <module>
    from flask_babel import lazy_gettext as lg
ModuleNotFoundError: No module named 'flask_babel'

It looks like I am not in the mycodo virtual environment, but I cannot find it with these commands:

lsvirtualenv -l
whereis python
cat ~/virtualenvs
lsvirtualenv

I know it is here ~/Mycodo/env.

Solution is to use python inside Mycodo env like this:

sudo ~/Mycodo/env/bin/python /home/pi/Mycodo/mycodo/user_python_code/conditional_045edd83-4918-4ef5-beda-fa11a3b5c52c.py