I have a python script that is running without a hitch in my development environment (PyCharm with venv) but as soon as I move it to a server, where it is meant to run as a service, it fails.
Excerpt from the code:
import configparser
config_file = "config.ini"
config = configparser.ConfigParser()
config.read(config_file)
mqtt_broker = config["mqtt_broker"]["address"]
The config.ini looks like this:
[mqtt_broker]
address = 10.0.0.10:1883
# maximum wait in milliseconds before raising an error
maximum_wait_ms = 3000
When I run it on the server (with user mqtt), I get:
$ sudo runuser -l mqtt -c "/etc/mqtt_kafka_bridge/venv/bin/python3.9 /etc/mqtt_kafka_bridge/venv/main.py --serve-in-foreground -log.level=debug"
Traceback (most recent call last):
File "/etc/mqtt_kafka_bridge/venv/main.py", line 19, in <module>
mqtt_broker = config["mqtt_broker"]["address"]
File "/usr/lib/python3.9/configparser.py", line 963, in __getitem__
raise KeyError(key)
KeyError: 'mqtt_broker'
Note: The whole virtual environment has been copied from the development environment onto the server. Moreover:
eric@ubuntu-server:~$ /etc/mqtt_kafka_bridge/venv/bin/python3 -m site
sys.path = [
'/home/eric',
'/usr/lib/python39.zip',
'/usr/lib/python3.9',
'/usr/lib/python3.9/lib-dynload',
'/etc/mqtt_kafka_bridge/venv/lib/python3.9/site-packages',
]
USER_BASE: '/home/eric/.local' (exists)
USER_SITE: '/home/eric/.local/lib/python3.9/site-packages' (doesn't exist)
ENABLE_USER_SITE: False
eric@ubuntu-server:~$ python3 -m site
sys.path = [
'/home/eric',
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
'/home/eric/.local/lib/python3.8/site-packages',
'/usr/local/lib/python3.8/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/eric/.local' (exists)
USER_SITE: '/home/eric/.local/lib/python3.8/site-packages' (exists)
ENABLE_USER_SITE: True
The server is running Ubuntu 20.04 LTS, which does not include Python3.9. This was installed later.
What am I not seeing? Thanks.