当我在虚拟环境之外运行此代码时,它可以工作。但是,当我尝试在虚拟环境中运行它时,我收到错误。我用谷歌搜索了几个小时的 ChatGPT。没有成功。有什么想法吗?
代码运行:
from gpiozero import LED
from time import sleep
from signal import signal, SIGTERM, SIGHUP, pause
def safe_exit(signum, frame):
exit(1)
red = LED(26)
def flashingLights():
while True:
red.on()
收到错误
/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/devices.py:300: PinFactoryFallback: Falling back from lgpio: module 'lgpio' has no attribute 'SET_BIAS_DISABLE'
warnings.warn(
Traceback (most recent call last):
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/pins/pi.py", line 411, in pin
pin = self.pins[info]
~~~~~~~~~^^^^^^
KeyError: PinInfo(number=37, name='GPIO26', names=frozenset({'BOARD37', 'WPI25', 'GPIO26', '26', 26, 'J8:37', 'BCM26'}), pull='', row=19, col=1, interfaces=frozenset({'', 'sdio', 'gpio', 'dpi', 'spi', 'jtag'}))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/cisco/Desktop/ledlight.py", line 8, in <module>
red = LED(26)
^^^^^^^
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/devices.py", line 108, in __call__
self = super().__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/output_devices.py", line 192, in __init__
super().__init__(pin, active_high=active_high,
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/output_devices.py", line 74, in __init__
super().__init__(pin, pin_factory=pin_factory)
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/mixins.py", line 75, in __init__
super().__init__(*args, **kwargs)
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/devices.py", line 553, in __init__
pin = self.pin_factory.pin(pin)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/pins/pi.py", line 413, in pin
pin = self.pin_class(self, info)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cisco/Desktop/myenv/lib/python3.11/site-packages/gpiozero/pins/rpigpio.py", line 101, in __init__
GPIO.setup(self._number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
RuntimeError: Cannot determine SOC peripheral base address
(myenv) cisco@raspberrypi:~/Desktop $
我的需求文件:
arandr 0.1.11
asgiref 3.7.2
av 11.0.0
Babel 2.14.0
beautifulsoup4 4.12.3
blinker 1.7.0
certifi 2024.2.2
cffi 1.16.0
chardet 5.2.0
charset-normalizer 3.3.2
click 8.1.7
colorama 0.4.6
colorzero 2.0
cryptography 42.0.5
cupshelpers 1.0
dbus-python 1.3.2
distro 1.9.0
Flask 3.0.2
gpiozero 2.0.1
html5lib 1.1
idna 3.6
importlib_metadata 7.0.2
itsdangerous 2.1.2
Jinja2 3.1.3
lgpio 0.0.0.2
libevdev 0.11
lxml 5.1.0
MarkupSafe 2.1.5
more-itertools 10.2.0
numpy 1.26.4
oauthlib 3.2.2
olefile 0.47
pexpect 4.9.0
pgzero 1.2.1
picamera2 0.3.17
pidng 4.0.9
piexif 1.1.3
pigpio 1.78
pillow 10.2.0
pip 24.0
ptyprocess 0.7.0
pycairo 1.20.1
pycparser 2.21
pycups 2.0.1
pygame 2.5.2
PyGObject 3.42.2
pyinotify 0.9.6
PyJWT 2.8.0
PyOpenGL 3.1.7
pyOpenSSL 24.0.0
PyQt5 5.15.9
PyQt5_sip 12.13.0
pyserial 3.5
pysmbc 1.0.23
python-apt 2.6.0
python-dotenv 1.0.1
python-prctl 1.8.1
pytz 2024.1
pyudev 0.24.1
PyYAML 6.0.1
reportlab 4.1.0
requests 2.31.0
requests-oauthlib 1.3.1
responses 0.25.0
RPi.GPIO 0.7.1
rpi-lcd 0.0.3
RTIMULib 7.2.1
sense-hat 2.6.0
setuptools 66.1.1
simplejpeg 1.7.2
simplejson 3.19.2
six 1.16.0
smbus 1.1.post2
smbus2 0.4.3
soupsieve 2.5
spidev 3.6
ssh-import-id 5.11
toml 0.10.2
twython 3.9.1
typing_extensions 4.10.0
urllib3 2.2.1
v4l2-python3 0.3.4
webencodings 0.5.1
Werkzeug 3.0.1
wheel 0.42.0
zipp 3.17.0
我有几个问题:
1)您的需求文件是否只包含必要的依赖项,
或者还有一些项目中没有用到的?
2) 您是否尝试过将 PIN 名称作为参数传递?
red = LED('GPIO26')