How to execute a python script from django management commands? -


i'm trying execute python script not inside django project directory... example management class call command:

i need run root because needs access gpio pins on raspberry pi. (and error)

(env) sudo python manage.py bubbles 

which calls script: execfile('/home/pi/rpi/bubbles.py')

# /home/pi/djangoprojects/raspberrypi/graphics/management/commands  django.core.management.base import basecommand, commanderror django.core.management.base import basecommand graphics.models import graphic   class command(basecommand):      = "my test command"      def handle(self, *args, **options):          execfile('/home/pi/rpi/bubbles.py') 

i error

traceback (most recent call last):    file "manage.py", line 8, in <module>  django.core.management import execute_from_command_line importerror: no module named django.core.management 

so i'm guessing problem virtual environment, there no way execute script outside scope of virtual environment? there better way execute script using django command or else. making sense @ all.

python script i'm trying call:

#!/usr/bin/env python  import image import imagedraw import time rgbmatrix import adafruit_rgbmatrix  # rows , chain length both required parameters: matrix = adafruit_rgbmatrix(16, 2)  # bitmap example w/graphics prims image = image.new("1", (16, 64)) # can larger matrix if wanted!! draw  = imagedraw.draw(image)    # declare draw instance before prims   # 24-bit rgb scrolling example. # adafruit.png image has couple columns of black pixels @ # right edge, erasing after scrolled image isn't necessary. while true:      matrix.clear()     image = image.open("bubbles.png")     image.load()     n in range(64, -image.size[0], -1):         matrix.setimage(image.im.id, n, 1)         time.sleep(0.025)      matrix.clear() 

maybe i'm going in wrong way, i'm learning incorporate web framework raspberry pi.

in bubbles.py, instead of doing this

def handle(self, *args, **options):      execfile('/home/pi/rpi/bubbles.py') 

try this

def handle(self, *args, **options):      execfile('path_to_your_env/bin/python /home/pi/rpi/bubbles.py') 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -