Python 没有名为';串行';
我有一段Python3代码运行在使用串行库的Pi3B+和Raspbian Buster上。 我用计算机导入了这个库Python 没有名为';串行';,python,python-3.x,pyserial,Python,Python 3.x,Pyserial,我有一段Python3代码运行在使用串行库的Pi3B+和Raspbian Buster上。 我用计算机导入了这个库 sudo apt-get install python3-serial Python脚本被放置在…/domoticz/scripts/Python/script\u time\u test.py中,以便每分钟都激活它 如果我在Thonny中运行这段代码,那么所有库都将顺利导入。 但是,如果Domaintics sceduler启动脚本,则raspbian发行版附带的所有标准库都会
sudo apt-get install python3-serial
Python脚本被放置在…/domoticz/scripts/Python/script\u time\u test.py中,以便每分钟都激活它
如果我在Thonny中运行这段代码,那么所有库都将顺利导入。
但是,如果Domaintics sceduler启动脚本,则raspbian发行版附带的所有标准库都会顺利导入,但串行库最终会出现错误。
在Stretch和Buster上的结果是相同的
代码目前只包含导入命令
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
import json
import os.path
import shutil
import threading
import time
import serial
2019-10-29 09:37:00.162 Error: EventSystem: Failed to execute python event script "/home/pi/domoticz/scripts/python/script_time_VirtDev.py"
2019-10-29 09:37:00.162 Error: EventSystem: Traceback (most recent call last):
2019-10-29 09:37:00.162 Error: EventSystem: File "/home/pi/domoticz/scripts/python/script_time_VirtDev.py", line 10, in <module>
2019-10-29 09:37:00.162 Error: EventSystem: import serial
2019-10-29 09:37:00.162 Error: EventSystem: ImportError: No module named 'serial'
环境多莫蒂茨
environ({
'PWD': '/',
'PATH': '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin',
'LANG': 'en_GB.UTF-8',
'INVOCATION_ID': 'ed8e00a2ea7943249b6c18f40f3e9c5e',
'JOURNAL_STREAM': '8:12744'
})
按计划作业导入的模块
Please wait a moment while I gather a list of all available modules...
CDROM _tracemalloc hashlib script_tiHR930-P3Dom
DLFCN _warnings heapq script_time_VirtDev
Domoticz _weakref hmac script_time_demo
DomoticzEvents _weakrefset html select
IN abc http selectors
TYPES aifc idlelib shelve
__future__ antigravity imaplib shlex
_ast argparse imghdr shutil
_bisect array imp signal
_bootlocale ast importlib site
_bz2 asynchat inspect sitecustomize
_codecs asyncio io smtpd
_codecs_cn asyncore ipaddress smtplib
_codecs_hk atexit itertools sndhdr
_codecs_iso2022 audioop json socket
_codecs_jp base64 keyword socketserver
_codecs_kr bdb lib2to3 spwd
_codecs_tw binascii linecache sqlite3
_collections binhex locale sre_compile
_collections_abc bisect logging sre_constants
_compat_pickle builtins lzma sre_parse
_compression bz2 macpath ssl
_crypt cProfile macurl2path stat
_csv calendar mailbox statistics
_ctypes cgi mailcap string
_ctypes_test cgitb marshal stringprep
_curses chunk math struct
_curses_panel cmath mimetypes subprocess
_datetime cmd mmap sunau
_dbm code modulefinder symbol
_decimal codecs multiprocessing symtable
_dummy_thread codeop netrc sys
_elementtree collections nis sysconfig
_functools colorsys nntplib syslog
_hashlib compileall ntpath tabnanny
_heapq concurrent nturl2path tarfile
_imp configparser numbers telnetlib
_io contextlib opcode tempfile
_json copy operator termios
_locale copyreg optparse test
_lsprof crypt os textwrap
_lzma csv ossaudiodev this
_markupbase ctypes parser threading
_md5 curses pathlib time
_multibytecodec datetime pdb timeit
_multiprocessing dbm pickle tkinter
_opcode decimal pickletools token
_operator difflib pipes tokenize
_osx_support dis pkgutil trace
_pickle distutils platform traceback
_posixsubprocess doctest plistlib tracemalloc
_pydecimal domoticz poplib tty
_pyio dummy_threading posix turtle
_random email posixpath types
_sha1 encodings pprint typing
_sha256 ensurepip profile unicodedata
_sha512 enum pstats unittest
_signal errno pty urllib
_sitebuiltins faulthandler pwd uu
_socket fcntl py_compile uuid
_sqlite3 filecmp pyclbr venv
_sre fileinput pydoc warnings
_ssl fnmatch pydoc_data wave
_stat formatter pyexpat weakref
_string fpectl queue webbrowser
_strptime fractions quopri wsgiref
_struct ftplib random xdrlib
_symtable functools re xml
_sysconfigdata gc readline xmlrpc
_sysconfigdata_m genericpath reloader xxlimited
_testbuffer getopt reprlib xxsubtype
_testcapi getpass resource zipapp
_testimportmultiple gettext rlcompleter zipfile
_testmultiphase glob runpy zipimport
_thread googlepubsub sched zlib
_threading_local grp script__testWHR930
_tkinter gzip script_device_demo
最后我发现了。串行软件包在不同的位置安装了多次,这导致了问题。我卸载、删除并清除了所有版本。 为了让事情顺利进行,我必须使用
sudo-apt-get-install-python3-serial安装程序,而不是pip安装程序,因为pip在python2.7文件夹中安装了python3包。简单答案是什么
pip install pyserial
我不熟悉Domoticz——它在运行时是否使用了某种虚拟环境,这意味着不会安装serial?因为所有其他人都是python@urbanespaceman据我所知没有。我正朝着同一个方向看。这个非python串行库有什么特别之处。或者可能是运行脚本的用户拥有或没有访问库的权限。如果我通过Thonny运行脚本,我就是用户Pi。Domotics是一个由root运行的执事。但是,如果domoticz生成一个进程来运行脚本,那么它是否也以root身份运行。也许您要查找的是pySerial
:python-m pip install pySerial
:@Silveris,这是完全相同的包。您可以使用apt get install将其作为debian软件包安装,也可以使用pip安装。结果是一样的。我已经尝试了这两种安装方法。你能安装一些其他的东西(不管是什么-一些小的东西)并将其导入到你的脚本中吗?看看这是否是一个特定的串行问题。如果不是(我怀疑),那么我们正在研究与您的调度程序在其中运行的环境有关的内容。。。
pip install pyserial