python sys.path different per user account - ImportError no module named (Focal, Bionic Beaver, and Xenial)

Bug #1869115 reported by OwN
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python2.7 (Ubuntu)
New
Undecided
Unassigned

Bug Description

In Ubuntu 20.04, python scripts executed by other users or users that cannot log in (/usr/sbin/nologin as their shell) do NOT work when importing modules that have been installed via python packages via apt or pip due to sys.path returning different values.

For example, I have a PAM python script that is used for authentication, and when it is run, it fails because it cannot find some of the modules it needs.

Further investigation shows that my current logged in user (running the script via the terminal) has a sys.path value of:

/current/directory/user/is/in
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages

When I run the same script with another user:

/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload

Two critical paths are missing for this user! They are:

/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages

Why are these two paths not included for this particular user?

I don't have this problem in older versions of Ubuntu. The same python script works in 18.04, but fails in 20.04.

Tags: path python sys
OwN (own3mall)
summary: - python sys.path different per user account - no module named
+ python sys.path different per user account - ImportError no module named
summary: python sys.path different per user account - ImportError no module named
+ (Focal)
Revision history for this message
OwN (own3mall) wrote : Re: python sys.path different per user account - ImportError no module named (Focal)

This is now an issue in Ubuntu 18.04 as well. I'm guessing whatever broke was backported into 18.04 as well.

See these scripts as examples:

Version for 18.04 and 20.04:

https://raw.githubusercontent.com/earnolmartin/EHCP-Force-Edition/master/ehcp/etc/pam/pam_dbauth_vsftpd_ubuntu_20_plus.py

Version for 16.04:

https://raw.githubusercontent.com/earnolmartin/EHCP-Force-Edition/master/ehcp/etc/pam/pam_dbauth_vsftpd.py

Difference is that in 18.04 and 20.04, I must set the path in the script:

sys.path.insert(0, '/usr/local/lib/python2.7/dist-packages')
sys.path.insert(0, '/usr/lib/python2.7/dist-packages')

If I do not, I get this error:

Sep 26 19:10:41 host /etc/security/pam_dbauth_smtp.py[9965]: Traceback (most recent call last):
Sep 26 19:10:41 host /etc/security/pam_dbauth_smtp.py[9965]: File "/etc/security/pam_dbauth_smtp.py", line 64, in <module>
Sep 26 19:10:41 host /etc/security/pam_dbauth_smtp.py[9965]: from passlib.hash import mysql41
Sep 26 19:10:41 host /etc/security/pam_dbauth_smtp.py[9965]: ImportError: No module named passlib.hash
Sep 26 19:10:41 host saslauthd[9965]: DEBUG: auth_pam: pam_authenticate failed: Error in service module

OwN (own3mall)
summary: python sys.path different per user account - ImportError no module named
- (Focal)
+ (Focal and Bionic Beaver)
Revision history for this message
OwN (own3mall) wrote :

Bug is now prevalent in Ubuntu 16.04 Xenial. Looks like whatever change has broken this has made it all the way to Ubuntu 16.04. How come this hasn't been fixed yet? This is such a breaking and critical bug! For it to be in three major versions of Ubuntu is embarrassing.

summary: python sys.path different per user account - ImportError no module named
- (Focal and Bionic Beaver)
+ (Focal, Bionic Beaver, and Xenial)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.