netplan not working after change default python

Viewed 2177

in ubuntu 18.04, when i change default python from python 3.6 to other version by this command:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1

or when i remove python 3.6 and install other version netplan apply not working and result this error:

  File "/usr/sbin/netplan", line 20, in <module>
    from netplan import Netplan
  File "/usr/share/netplan/netplan/__init__.py", line 18, in <module>
    from netplan.cli.core import Netplan
  File "/usr/share/netplan/netplan/cli/core.py", line 24, in <module>
    import netplan.cli.utils as utils
  File "/usr/share/netplan/netplan/cli/utils.py", line 25, in <module>
    import netifaces
ModuleNotFoundError: No module named 'netifaces'

and command pip install netifaces has some errors.

2 Answers

I faced the same issue before with vagrant. If you use update-alternatives to make python3 alias points to another version of Python, vagrant will not work. You cannot use update-alternatives to change the alias of Python3.

For some reason I lost my python configuration after an update made by my ubuntu server,solved by:

Checking if I could import the module so on CLI:

python
import python

After getting the same message I realize my python environment was falling to use the modules even when it all showed up as installed I went ahead and "upgrade" the python modules:

python pip install --upgrade pip

python pip install --upgrade netifaces

python pip install --upgrade "any module you need to use for your script"

And just like that modules were recognized updated and properly install.

Related