RobD
RobD

Reputation: 105

No module named 'serial'

I have a piece of Python3 code running on a Pi3B+ with Raspbian Buster that uses the serial library. I imported this library with

sudo apt-get install python3-serial

The Python script is placed in .../domoticz/scripts/python/script_time_test.py to activate it every minute bij de Domoticz scheduler.

If I run this piece of code in Thonny all libraries are imported without problems. However if the Domotics sceduler starts the scripts, all standard libraries that come with the raspbian distribution are imported without problems but the serial library ends up with the error. The results are the same on Stretch and Buster

The code contains at this moment only import commands

#!/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'

environment Thonny

environ({
'DESKTOP_SESSION': 'LXDE-pi', 
'XDG_SESSION_TYPE': 'x11', 
'INFINALITY_FT_GLOBAL_EMBOLDEN_Y_VALUE': '0', 
'THONNY_USER_DIR': '/home/pi/.thonny', 
'INFINALITY_FT_AUTOHINT_SNAP_STEM_HEIGHT': '100', 
'SHELL': '/bin/bash', 
'INFINALITY_FT_GLOBAL_EMBOLDEN_X_VALUE': '0', 
'XDG_MENU_PREFIX': 'lxde-pi-', 
'INFINALITY_FT_USE_KNOWN_SETTINGS_ON_SELECTED_FONTS': 'true', 
'INFINALITY_FT_STEM_ALIGNMENT_STRENGTH': '25', 
'INFINALITY_FT_FILTER_PARAMS': '11 22 38 22 11', 
'INFINALITY_FT_AUTOHINT_VERTICAL_STEM_DARKEN_STRENGTH': '25', 
'_LXSESSION_PID': '654', 
'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus', 
'INFINALITY_FT_STEM_SNAPPING_SLIDING_SCALE': '40', 
'SAL_USE_VCLPLUGIN': 'gtk', 
'TEXTDOMAIN': 'Linux-PAM', 
'XDG_SESSION_PATH': '/org/freedesktop/DisplayManager/Session0', 
'XDG_VTNR': '7', 
'PYTHONIOENCODING': 'ASCII', 
'XDG_SESSION_DESKTOP': 'lightdm-xsession', 
'XDG_GREETER_DATA_DIR': '/var/lib/lightdm/data/pi', 
'INFINALITY_FT_FRINGE_FILTER_STRENGTH': '0', 
'XDG_CURRENT_DESKTOP': 'LXDE', 
'LANG': 'en_GB.UTF-8', 
'DESKTOP_STARTUP_ID': 'pcmanfm-860-raspberrypi-/usr/bin/thonny-3_TIME101146699', 
'HOME': '/home/pi', 
'GPG_AGENT_INFO': '/run/user/1000/gnupg/S.gpg-agent:0:1', 
'XAUTHORITY': '/home/pi/.Xauthority', 
'XDG_DATA_DIRS': '/usr/local/share:/usr/share/raspi-ui-overrides:/usr/share:/usr/share/gdm:/var/lib/menu-xdg', 
'INFINALITY_FT_CHROMEOS_STYLE_SHARPENING_STRENGTH': '0', 
'SSH_AUTH_SOCK': '/tmp/ssh-SpT8Yoekyndc/agent.654', 
'INFINALITY_FT_GAMMA_CORRECTION': '0 100', 
'INFINALITY_FT_AUTOHINT_INCREASE_GLYPH_HEIGHTS': 'true', 
'XDG_SEAT_PATH': '/org/freedesktop/DisplayManager/Seat0', 
'GDMSESSION': 'lightdm-xsession', 
'USER': 'pi', 
'XDG_CONFIG_DIRS': '/etc/xdg', 
'INFINALITY_FT_STEM_FITTING_STRENGTH': '25', 
'XDG_SESSION_ID': 'c1', 
'PYTHONUNBUFFERED': '1', 
'INFINALITY_FT_CONTRAST': '0', 
'SSH_AGENT_PID': '826', 
'PWD': '/home/pi', 
'INFINALITY_FT_BRIGHTNESS': '0', 
'INFINALITY_FT_BOLD_EMBOLDEN_X_VALUE': '0', 
'DISPLAY': ':0.0', 
'INFINALITY_FT_BOLD_EMBOLDEN_Y_VALUE': '0', 
'XDG_RUNTIME_DIR': '/run/user/1000', 
'INFINALITY_FT_WINDOWS_STYLE_SHARPENING_STRENGTH': '10', 
'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games','INFINALITY_FT_AUTOHINT_HORIZONTAL_STEM_DARKEN_STRENGTH': '10', 
'INFINALITY_FT_USE_VARIOUS_TWEAKS': 'true', 
'INFINALITY_FT_GRAYSCALE_FILTER_STRENGTH': '0', 
'XDG_CONFIG_HOME': '/home/pi/.config', 
'XDG_SEAT': 'seat0', 
'LOGNAME': 'pi'
})

environment Domoticz

environ({
'PWD': '/', 
'PATH': '/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin', 
'LANG': 'en_GB.UTF-8', 
'INVOCATION_ID': 'ed8e00a2ea7943249b6c18f40f3e9c5e', 
'JOURNAL_STREAM': '8:12744'
})

imported modules by the scheduled job


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  

Upvotes: 0

Views: 5490

Answers (2)

dragon445
dragon445

Reputation: 119

simple answer?

pip install pyserial

Upvotes: 0

RobD
RobD

Reputation: 105

Finally I found out. The serial package was installed multiple times in different locations and that caused the problem. I uninstalled, removed and purged all versions. To get things working I had to install with sudo apt-get install python3-serial and not the pip installer, because pip installed the python3 package in the python2.7 folders.

Upvotes: 1

Related Questions