Linux : OpenVPN error can’t find module ‘pyovpn’ after upgrading Debian 10 to 11

By | October 21, 2023

If you were running OpenVPN 2.x on Debian 10 successfully and it suddently broke with the following error after upgrading to Debian 11 :

Oct 21 11:34:12 ovpnserver openvpnas[32211]: Traceback (most recent call last):
Oct 21 11:34:12 ovpnserver openvpnas[32211]:   File "<string>", line 1, in <module>
Oct 21 11:34:12 ovpnserver openvpnas[32211]:   File "<frozen zipimport>", line 241, in load_module
Oct 21 11:34:12 ovpnserver openvpnas[32211]:   File "<frozen zipimport>", line 721, in _get_module_code
Oct 21 11:34:12 ovpnserver openvpnas[32211]: zipimport.ZipImportError: can't find module 'pyovpn'
Oct 21 11:34:12 ovpnserver systemd[1]: openvpnas.service: Main process exited, code=exited, status=1/FAILURE
Oct 21 11:34:12 ovpnserver systemd[1]: openvpnas.service: Failed with result 'exit-code'.

This is because you still have the old OpenVPN Debian 10 repository configured in APT.  In order to resolve that issue, we simply need to update the repo and update OpenVPN from the new repo.

1. Validate the installed packages :

# dpkg -l | grep openvpn
rc  openvpn                               2.4.9-buster0                    amd64        virtual private network daemon
ii  openvpn-as                            2.12.1-bc070def-Debian10         amd64        OpenVPN Access Server integrated VPN Server solution
ii  openvpn-as-bundled-clients            28                               all          OpenVPN Access Server bundled clients

As we can see, we have Debian 10 (Buster) package version currently installed, but running Debian 11 (Bullseye).

2. Let’s validate the repo :

# cat /etc/apt/sources.list.d/openvpn-aptrepo.list
deb http://as-repository.openvpn.net/as/debian buster main

The repo is indeed set for Debian 10 Buster… we need to change that to Debian 11 Bullseye.

3. Disable the current repo :

mv /etc/apt/sources.list.d/openvpn-aptrepo.list /etc/apt/sources.list.d/openvpn-aptrepo.list.old

4. Make sure OpenVPN requirements are presents :

apt update && apt -y install ca-certificates wget net-tools gnupg

5. Import the repo signature :

wget https://as-repository.openvpn.net/as-repo-public.asc -qO /etc/apt/trusted.gpg.d/as-repository.asc

6. Configure the APT repo :

echo "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/as-repository.asc] http://as-repository.openvpn.net/as/debian bullseye main">/etc/apt/sources.list.d/openvpn-as-repo.list

7. Update repos and OpenVPN :

apt update && apt -y upgrade openvpn-as

8. Validate that OpenVPN started successfully :

# systemctl status openvpnas
● openvpnas.service - OpenVPN Access Server
     Loaded: loaded (/lib/systemd/system/openvpnas.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-10-21 11:39:01 EDT; 55s ago
   Main PID: 34545 (python3)
      Tasks: 18 (limit: 9389)
     Memory: 243.8M
        CPU: 5.147s
     CGroup: /system.slice/openvpnas.service
             ├─34545 python3 -c from pyovpn.sagent.sagent_entry import openvpnas ; openvpnas() --nodaemon --logfile=/var/log/openvpnas.log --pidfile=
             ├─34564 /usr/bin/python3 -c from pyovpn.cserv.wserv_entry import start ; start() -no -u openvpn_as -g openvpn_as --pidfile /usr/local/openvpn_as/etc/tmp/wserv.pid
             ├─34565 /usr/bin/python3 -c from pyovpn.log.logworker import start ; start()
             ├─34588 /usr/bin/python3 -c from pyovpn.sagent.iptworker import start6 ; start6()
             ├─34589 /usr/bin/python3 -c from pyovpn.sagent.iptworker import start ; start()
             ├─34592 openvpn-openssl --errors-to-stderr --config stdin
             ├─34596 openvpn-openssl --errors-to-stderr --config stdin
             ├─34627 openvpn-openssl --errors-to-stderr --config stdin
             ├─34638 openvpn-openssl --errors-to-stderr --config stdin
             ├─34699 openvpn-openssl --errors-to-stderr --config stdin
             ├─34708 openvpn-openssl --errors-to-stderr --config stdin
             ├─34766 openvpn-openssl --errors-to-stderr --config stdin
             ├─34776 openvpn-openssl --errors-to-stderr --config stdin
             ├─34833 openvpn-openssl --errors-to-stderr --config stdin
             ├─34894 openvpn-openssl --errors-to-stderr --config stdin
             ├─34953 openvpn-openssl --errors-to-stderr --config stdin
             ├─35018 openvpn-openssl --errors-to-stderr --config stdin
             └─35071 iptables-restore -n

Oct 21 11:39:01 ovpnserver systemd[1]: Started OpenVPN Access Server.

9. Delete the old repo file :

rm -f /etc/apt/sources.list.d/openvpn-aptrepo.list.old