Score:0

Installing Azure Linux Agent gives python related issues

in flag

When I got this server assigned, it has two versions of python (2.7 and 3.6), then I had to install 3.10 manually because the version of Netbox I want to use needed 3.8 minimum.

Everything looked fine, until I realized that walinuxagent (Azure Linux Agent) is not working. It seems there's an issue with python.

Azure Linux Agent

  • I have apt remove --purge walinuxagent and reinstalled via apt install walinuxagent but still not working:
$ sudo systemctl status walinuxagent.service

● walinuxagent.service - Azure Linux Agent
   Loaded: loaded (/lib/systemd/system/walinuxagent.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/walinuxagent.service.d
           └─10-Slice.conf, 11-CPUAccounting.conf, 12-CPUQuota.conf
   Active: failed (Result: exit-code) since Wed 2023-02-01 15:19:50 UTC; 15s ago
  Process: 29518 ExecStart=/usr/bin/python3 -u /usr/sbin/waagent -daemon (code=exited, status=1/FAILURE)
 Main PID: 29518 (code=exited, status=1/FAILURE)
      CPU: 76ms

Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Service hold-off time over, scheduling restart.
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Scheduled restart job, restart counter is at 5.
Feb 01 15:19:50 SERVER-01 systemd[1]: Stopped Azure Linux Agent.
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Consumed 76ms CPU time
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Start request repeated too quickly.
Feb 01 15:19:50 SERVER-01 systemd[1]: walinuxagent.service: Failed with result 'exit-code'.
Feb 01 15:19:50 SERVER-01 systemd[1]: Failed to start Azure Linux Agent.
  • This is the result of journalctl -u walinuxagent.service:
-- Logs begin at Thu 2022-12-15 11:18:50 UTC, end at Wed 2023-02-01 15:28:33 UTC. --
Jan 31 10:03:55 SERVER-01 systemd[1]: Started Azure Linux Agent.
Jan 31 10:03:55 SERVER-01 python3[930]: /usr/sbin/waagent:27: DeprecationWarning: the imp module is deprecated in favour
Jan 31 10:03:55 SERVER-01 python3[930]:   import imp
Jan 31 10:03:56 SERVER-01 python3[930]: Traceback (most recent call last):
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 43Jan 31 10:03:56 SERVER-01 python3[930]:     supported = platform._supported_dists + (supported_dists,)
Jan 31 10:03:56 SERVER-01 python3[930]: AttributeError: module 'platform' has no attribute '_supported_dists'
Jan 31 10:03:56 SERVER-01 python3[930]: During handling of the above exception, another exception occurred:
Jan 31 10:03:56 SERVER-01 python3[930]: Traceback (most recent call last):
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/sbin/waagent", line 31, in <module>
Jan 31 10:03:56 SERVER-01 python3[930]:     import azurelinuxagent.agent as agent
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/agent.py", line 34, in <moJan 31 10:03:56 SERVER-01 python3[930]:     import azurelinuxagent.common.event as event
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/event.py", line 34,Jan 31 10:03:56 SERVER-01 python3[930]:     from azurelinuxagent.common.version import CURRENT_VERSION, CURRENT_AGENT
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/version.py", line 1Jan 31 10:03:56 SERVER-01 python3[930]:     __distro__ = get_distro()
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/version.py", line 8Jan 31 10:03:56 SERVER-01 python3[930]:     osinfo = get_linux_distribution(0, 'alpine')
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 61Jan 31 10:03:56 SERVER-01 python3[930]:     return get_linux_distribution_from_distro(get_full_name)
Jan 31 10:03:56 SERVER-01 python3[930]:   File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 72Jan 31 10:03:56 SERVER-01 python3[930]:     distro.linux_distribution(
Jan 31 10:03:56 SERVER-01 python3[930]: NameError: name 'distro' is not defined
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Main process exited, code=exited, status=1/FAILURE
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Failed with result 'exit-code'.
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Consumed 125ms CPU time
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Service hold-off time over, scheduling restart.
Jan 31 10:03:56 SERVER-01 systemd[1]: walinuxagent.service: Scheduled restart job, restart counter is at 1.
Jan 31 10:03:56 SERVER-01 systemd[1]: Stopped Azure Linux Agent.
$ sudo python3 setup.py install

Traceback (most recent call last):
  File "/home/admin/Azure/WALinuxAgent-master/setup.py", line 24, in <module>
    import setuptools
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 12, in <module>
    import setuptools.version
  File "/usr/lib/python3/dist-packages/setuptools/version.py", line 1, in <module>
    import pkg_resources
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 77, in <module>
    __import__('pkg_resources.extern.packaging.requirements')
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 632, in _load_backward_compatible
  File "/usr/lib/python3/dist-packages/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/pyparsing.py", line 943, in <module>
    collections.MutableMapping.register(ParseResults)
AttributeError: module 'collections' has no attribute 'MutableMapping'

Python

  • whereis python output:
python: /usr/bin/python3.6m-config /usr/bin/python3.10 /usr/bin/python3.6-config /usr/bin/python /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python2.7 /usr/lib/python3.10 /usr/lib/python3.8 /usr/lib/python3.6 /usr/lib/python2.7 /usr/lib/python3.7 /etc/python3.10 /etc/python /etc/python3.6 /etc/python2.7 /usr/local/lib/python3.10 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.6m /usr/include/python3.6 /usr/share/python /usr/share/man/man1/python.1.gz 
  • ls -ls /usr/bin/python* output:
   0 lrwxrwxrwx 1 root root      24 Jan 31 15:53 /usr/bin/python -> /etc/alternatives/python
   0 lrwxrwxrwx 1 root root       9 Apr 16  2018 /usr/bin/python2 -> python2.7
3544 -rwxr-xr-x 1 root root 3628904 Nov 28 18:51 /usr/bin/python2.7
   0 lrwxrwxrwx 1 root root      25 Dec 15 10:41 /usr/bin/python3 -> /etc/alternatives/python3
   0 lrwxrwxrwx 1 root root      16 Oct 25  2018 /usr/bin/python3-config -> python3.6-config
   4 -rwxr-xr-x 1 root root    1018 Oct 28  2017 /usr/bin/python3-jsondiff
   4 -rwxr-xr-x 1 root root    3661 Oct 28  2017 /usr/bin/python3-jsonpatch
   4 -rwxr-xr-x 1 root root    1342 May  1  2016 /usr/bin/python3-jsonpointer
   4 -rwxr-xr-x 1 root root     398 Nov 15  2017 /usr/bin/python3-jsonschema
5352 -rwxr-xr-x 1 root root 5477688 Jan 28 19:09 /usr/bin/python3.10
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6
   0 lrwxrwxrwx 1 root root      33 Nov 25 14:10 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6m
   0 lrwxrwxrwx 1 root root      34 Nov 25 14:10 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
   0 lrwxrwxrwx 1 root root      10 Oct 25  2018 /usr/bin/python3m -> python3.6m
   0 lrwxrwxrwx 1 root root      17 Oct 25  2018 /usr/bin/python3m-config -> python3.6m-config
  • Python version listed:
$ python -V
Python 3.10.9

$ python3 -V
Python 3.10.9

$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.10

Does anyone have an idea of how can I resolve this?

UPDATE 1: the situation improved

I uninstalled Python 3.10.9, removed the symlinks and replaced with the python version that originally came with the OS, then I reconfigured update-alternatives of python and python3.

$ ls -ls /usr/bin/python*
   0 lrwxrwxrwx 1 root root      24 Feb  2 10:22 /usr/bin/python -> /etc/alternatives/python
   0 lrwxrwxrwx 1 root root       9 Apr 16  2018 /usr/bin/python2 -> python2.7
3544 -rwxr-xr-x 1 root root 3628904 Nov 28 18:51 /usr/bin/python2.7
   0 lrwxrwxrwx 1 root root      25 Feb  2 10:23 /usr/bin/python3 -> /etc/alternatives/python3
   0 lrwxrwxrwx 1 root root      16 Oct 25  2018 /usr/bin/python3-config -> python3.6-config
   4 -rwxr-xr-x 1 root root    1018 Oct 28  2017 /usr/bin/python3-jsondiff
   4 -rwxr-xr-x 1 root root    3661 Oct 28  2017 /usr/bin/python3-jsonpatch
   4 -rwxr-xr-x 1 root root    1342 May  1  2016 /usr/bin/python3-jsonpointer
   4 -rwxr-xr-x 1 root root     398 Nov 15  2017 /usr/bin/python3-jsonschema
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6
   0 lrwxrwxrwx 1 root root      33 Nov 25 14:10 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
4424 -rwxr-xr-x 2 root root 4526456 Nov 25 14:10 /usr/bin/python3.6m
   0 lrwxrwxrwx 1 root root      34 Nov 25 14:10 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
   0 lrwxrwxrwx 1 root root      10 Oct 25  2018 /usr/bin/python3m -> python3.6m
   0 lrwxrwxrwx 1 root root      17 Oct 25  2018 /usr/bin/python3m-config -> python3.6m-config
$ python -V
Python 2.7.17

$ python3 -V
Python 3.6.9
  • Now walinuxagent is running fine.
$ sudo systemctl status walinuxagent
● walinuxagent.service - Azure Linux Agent
   Loaded: loaded (/lib/systemd/system/walinuxagent.service; enabled; vendor preset: enabled)
  Drop-In: /lib/system/system/walinuxagent.service.d
           └─10-Slice.conf, 11-CPUAccounting.conf, 12-CPUQuota.conf, 13-MemoryAccounting.conf
   Active: active (running) since Thu 2023-02-02 10:29:31 UTC; 5s ago
 Main PID: 10593 (python3)
    Tasks: 7 (limit: 4915)
   Memory: 32.4M
      CPU: 920ms
   CGroup: /azure.slice/walinuxagent.service
           ├─10593 /usr/bin/python3 -u /usr/sbin/waagent -daemon
           └─10632 python3 -u bin/WALinuxAgent-2.9.0.4-py2.7.egg -run-exthandlers

the problem is that I need to upgrade fron pythoin 3.6 to python 3.8, 3.9, 3.10 or 3.11, without messing things up

UPDATE 2: A new issue

I managed to install python 3.6 alongside python 3.10, the problem is that when 3.6 is selected in update alternatives, walinuxagent service works fine when while netbox, netbox-rq and nginx services doesn't; the opposite happening when 3.10 is selected.

A workaround is selecting each python version depending on which service I want to start. Is there a way to avoiding doing this every time?

user535733 avatar
cn flag
Restore the original version of Python3 that came with Ubuntu. NEVER change it. Your Ubuntu system needs that specific version. How to run Py3.10 on this system is a different question with a fairly lengthy (but not difficult) answer.
in flag
@user535733 If I restore the original version of python, how can I upgrade to 3.8 or higher? I can't leave with 3.6 or things will not work properly.
karel avatar
sa flag
Does this answer your question? [How do I install Python 3.8 in Lubuntu 18.04?](https://askubuntu.com/questions/1197683/how-do-i-install-python-3-8-in-lubuntu-18-04)
in flag
@karel in the post you linked it say to a make a virtual environment and activate python 3.8 in it, will this work the same as having Python 3.8 installed for the applications that will need this version?
in flag
@karel can't I just install python 3.10 via apt and selecting both versions in `update-alternatives --config python` ?
karel avatar
sa flag
It's OK as long as the original Python version remains the default Python version in `update-alternatives --config python` because a lot of apps depend on the original Python version.
in flag
@karel that's fine, the important thing for me is the program I'm using on this server (netbox) will be able to use python 3.10 when he need it.
user535733 avatar
cn flag
AskUbuntu's Question/Answer format works best when you open a new question for a new issue. Your original question was about how to save your system when you changed the Python version.
in flag
@user535733 you must be right, I come from forum format, and trying to avoid creating too many questions
Score:0
pe flag
k7a

It's probably too late, but I solved this changing the configuration of the service to use the python version 3.6.

sudo nano /lib/systemd/system/walinuxagent.service
#Change python3 by pnone-reload
sudo systemctl restart walinuxagent
#and check that the service is working
sudo systemctl status walinuxagent
walinuxagent.service - Azure Linux Agent
   Loaded: loaded (/lib/systemd/system/walinuxagent.service; enabled; vend
  Drop-In: /lib/systemd/system/walinuxagent.service.d
           └─10-Slice.conf, 11-CPUAccounting.conf, 12-CPUQuota.conf, 13-Me
   Active: active (running) since Thu 2023-04-06 12:39:18 UTC; 11s ago
 Main PID: 15298 (python3.6)
    Tasks: 2 (limit: 4915)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.