New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't run a script without env variables. #591
Comments
This will work without environment variables if you have RPi.GPIO installed, as you do on Raspbian desktop by default, or Raspbian Lite (if you installed the apt package). If, however, you install with pip (either system-wide or in a virtualenv), it won't bring in RPi.GPIO, and no default pin factory will be loaded. So the documentation is correct, assuming you have RPI.GPIO installed as per Raspbian default. What happens when you do have RPi.GPIO installed is it happily loads RPi.GPIO as the default pin factory, and then you don't use it but instead manually set your LED's pin factory to a PiGPIO one. What happens when you don't have RPi.GPIO installed is it looks for RPi.GPIO (and fails), looks for RPIO (and fails), looks for pigpio (and finds it, but as no PIGPIO_ADDR is set, uses 'localhost' and if you don't have pigpiod running locally, it fails). So to use that script you need one of the following:
|
I installed RPI.GPIO but the problem remained. |
When I entering python on my Mac by:
then I testing if gpiozero works by performing:
the output it gives me is following:
I followed documentation until 4.3. Environment variables, after that I have no idea what to do. It tells to :
On my Client PC aka Mac I've got installed Python3.5 under Anaconda env, so I downloaded the whole gpiozero folder from GitHub into site-packages folder there, since the pip installation rather put it in default Mac python environment. Also Rpi running fine, I installed pigpen and activated remote gpis through the sudo raps-config menu. Currently I'm controlling it through ssh from my Mac terminal and being able to activate gpio just fine by performing: gpis mode X out, gpis write X 1. This is getting pretty frustrating, since there is not much help online after I tried to google nearly everything I could think of. Any idea how to fix this? And if there is please explain how to like you would to a 90 year old grandpa. Thanks. |
@Kaveshnikov What happens when you type |
@Herant Can you make sure pigpiod is running on the remote Pi and try |
@bennuttall I get this traceback: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi! It's obvious, because I type this on my PC. |
Ah, ok. So the issue is just that the documentation assumes you're on a Pi (it only works without environment variables if you're on a Pi). I'll amend that for the next release. |
@bennuttall if I understood you correctly, I replaced IP address with ip on my rpi, I also changed to "myenv3.5" which is where I git-hub'ed the install files and installed it. And yeah i did sudo pigpiod on rip first. Now, I ran this code and the answer I am getting is : (myenv3.5) Users-MacBook-Pro:V0.3 user1$ GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.1.130 pinout 0 |
@Herant You have a |
@bennuttall Oh, when u run from gpiozero import LED
from time import sleep
red = LED(17)
while True:
red.on()
sleep(1)
red.off()
sleep(1) which suppose to be test code according to documentation. When I run this code by typing: (myenv3.5) Users-MBP:Desktop user1$ PIGPIO_ADDR=192.168.1.130 python test.py I'm getting error:
|
That means it's working. The pinout information is actually from your remote Pi. Try the same environment variables when running your Python script: GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.1.130 python3 test.py |
@bennuttall when I'm trying to run GPIOZERO_PIN_FACTORY=pigpio PIGPIO_ADDR=192.168.1.130 python3 test.py I'm getting this:
I tried both with python3 and python, still same output. |
@Herant how exactly did you install pigpio? From that stack trace, it's claiming that ".../site-packages/pigpio.py" contains "from . import SPI" but the pigpio client library contains no relative imports. My guess (given that your method of installing gpiozero was to copy the source into your own site-packages), is that you copied However, assuming my guess is correct, I'd suggest just it's a lot easier to just use conda's built-in pip - it should be much simpler than copying stuff manually. |
@waveform80 Well it says that gpiozero is already installed.
|
Alright now it works, all I did was |
Remotely controlling a Pi from Windows 10 using GPIOZero. Ran in to a many of the above problems. Two Windows User Environmental Variables cleaned it up. First variable was Variable name: PIGPIO_ADDR, Variable value: 192.168.1.86. Not Variable value: 192.168.1.86 python. My Pi address is 192.168.1.86. Second was Variable name: GPIOZERO_PIN_FACTORY, Variable value: pigpio. This cured the PinFactoryFallback Falling back stuff. Also set the pin numbering scheme to Broadcom (BCM) pin numbering to be consistent with GPIOZero. Beyond that just the install steps from the GPIOZero documentation. Did find not all of the methods in the Recipes are supported. Example no pulse method for LED. |
I was following this recipe and got this:
So, is there a way to not use environment variables?
My script:
The text was updated successfully, but these errors were encountered: