0

Django プロジェクトディレクトリ内にない python スクリプトを実行しようとしています...たとえば、これはコマンドで呼び出す私の管理クラスです:

ラズベリーパイのGPIOピンにアクセスする必要があるため、これをROOTとして実行する必要があります。(そして、別のエラーが発生します)

(env) sudo python manage.py bubbles

このスクリプトを呼び出します: execfile('/home/pi/rpi/bubbles.py')

# /home/pi/DjangoProjects/RaspberryPi/graphics/management/commands

from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from graphics.models import Graphic


class Command(BaseCommand):

    help = "My test command"

    def handle(self, *args, **options):

        execfile('/home/pi/rpi/bubbles.py')

このエラーが発生します

Traceback (most recent call last):
   File "manage.py", line 8, in <module>
 from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

これは私の仮想環境の問題だと思いますが、仮想環境の範囲外でスクリプトを実行する方法はありませんか? django コマンドなどを使用してこのスクリプトを実行するより良い方法はありますか。私はまったく意味がありますか?

私が呼び出そうとしているpythonスクリプト:

#!/usr/bin/env python

import Image
import ImageDraw
import time
from rgbmatrix import Adafruit_RGBmatrix

# Rows and chain length are both required parameters:
matrix = Adafruit_RGBmatrix(16, 2)

# Bitmap example w/graphics prims
image = Image.new("1", (16, 64)) # Can be larger than matrix if wanted!!
draw  = ImageDraw.Draw(image)    # Declare Draw instance before prims


# 24-bit RGB scrolling example.
# The adafruit.png image has a couple columns of black pixels at
# the right edge, so erasing after the scrolled image isn't necessary.
while True:

    matrix.Clear()
    image = Image.open("bubbles.png")
    image.load()
    for n in range(64, -image.size[0], -1):
        matrix.SetImage(image.im.id, n, 1)
        time.sleep(0.025)

    matrix.Clear()

多分私はこれを間違った方法で行っているのかもしれません.私はウェブフレームワークを私のラズベリーパイに組み込むことを学んでいます.

4

1 に答える 1

0

これを行う代わりに、 bubble.pyで

def handle(self, *args, **options):

    execfile('/home/pi/rpi/bubbles.py')

これを試して

def handle(self, *args, **options):

    execfile('PATH_TO_YOUR_ENV/bin/python /home/pi/rpi/bubbles.py')
于 2016-05-25T05:35:50.473 に答える