Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not work on Ubuntu-based systems #22

Open
woutervh opened this issue Nov 16, 2023 · 4 comments
Open

does not work on Ubuntu-based systems #22

woutervh opened this issue Nov 16, 2023 · 4 comments

Comments

@woutervh
Copy link
Collaborator

Today I discovered Ubuntu ships the system python with a sitecustomize
that always takes precedence over the pip installed "sitecustomize-entrypoints", even in a virtualenv

└─$ python3
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sitecustomize as sc
>>> sc.__file__
'/usr/lib/python3.11/sitecustomize.py'
cat  /usr/lib/python3.11/sitecustomize.py:

# install the apport exception handler if available
try:
    import apport_python_hook
except ImportError:
    pass
else:
    apport_python_hook.install()

@Darsstar
Copy link
Owner

Is that in system python or a venv?

I'm 99.999% certain it is the former based on the output.

Distro's are putting up more and more walls to prevent users from altering the system Python via Pip. (I fully agree with this decision.) See PEP668.

@woutervh
Copy link
Collaborator Author

This is system-python + any virtualenv created from system-python.

the main problem is the location where ubuntu puts this sitecustomize: in the standard library

└─$ ll /usr/lib/python3.11
total 5080
-rw-r--r-- 1 root root   6538 Jun  7 12:13 abc.py
-rw-r--r-- 1 root root  34211 Jun  7 12:13 aifc.py
-rw-r--r-- 1 root root   3389 Jun  7 12:13 _aix_support.py
-rw-r--r-- 1 root root    500 Jun  7 12:13 antigravity.py
-rw-r--r-- 1 root root  99957 Jun  7 12:13 argparse.py
-rw-r--r-- 1 root root  60667 Jun  7 12:13 ast.py
-rw-r--r-- 1 root root  11570 Jun  7 12:13 asynchat.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 asyncio
-rw-r--r-- 1 root root  20310 Jun  7 12:13 asyncore.py
-rwxr-xr-x 1 root root  21027 Jun  7 12:13 base64.py
-rw-r--r-- 1 root root  32463 Jun  7 12:13 bdb.py
-rw-r--r-- 1 root root   3135 Jun  7 12:13 bisect.py
-rw-r--r-- 1 root root   2675 Jun  7 12:13 _bootsubprocess.py
-rw-r--r-- 1 root root  11847 Jun  7 12:13 bz2.py
-rw-r--r-- 1 root root  24745 Jun  7 12:13 calendar.py
-rwxr-xr-x 1 root root  34420 Jun  7 12:13 cgi.py
-rw-r--r-- 1 root root  12421 Jun  7 12:13 cgitb.py
-rw-r--r-- 1 root root   5500 Jun  7 12:13 chunk.py
-rw-r--r-- 1 root root  14873 Jun  7 12:13 cmd.py
-rw-r--r-- 1 root root  36714 Jun  7 12:13 codecs.py
-rw-r--r-- 1 root root   5599 Jun  7 12:13 codeop.py
-rw-r--r-- 1 root root  10622 Jun  7 12:13 code.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 collections
-rw-r--r-- 1 root root  30193 Jun  7 12:13 _collections_abc.py
-rw-r--r-- 1 root root   4022 Jun  7 12:13 colorsys.py
-rw-r--r-- 1 root root   8761 Jun  7 12:13 _compat_pickle.py
-rw-r--r-- 1 root root  20252 Jun  7 12:13 compileall.py
-rw-r--r-- 1 root root   5681 Jun  7 12:13 _compression.py
drwxr-xr-x 4 root root   4096 Aug 22 02:16 concurrent
-rw-r--r-- 1 root root  55254 Jun  7 12:13 configparser.py
-rw-r--r-- 1 root root  27076 Jun  7 12:13 contextlib.py
-rw-r--r-- 1 root root    129 Jun  7 12:13 contextvars.py
-rw-r--r-- 1 root root   8681 Jun  7 12:13 copy.py
-rw-r--r-- 1 root root   7677 Jun  7 12:13 copyreg.py
-rwxr-xr-x 1 root root   6346 Jun  7 12:13 cProfile.py
-rw-r--r-- 1 root root   3913 Jun  7 12:13 crypt.py
-rw-r--r-- 1 root root  16030 Jun  7 12:13 csv.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 ctypes
drwxr-xr-x 3 root root   4096 Aug 22 02:16 curses
-rw-r--r-- 1 root root  58299 Jun  7 12:13 dataclasses.py
-rw-r--r-- 1 root root  92003 Jun  7 12:13 datetime.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 dbm
-rw-r--r-- 1 root root    320 Jun  7 12:13 decimal.py
-rw-r--r-- 1 root root  83308 Jun  7 12:13 difflib.py
-rw-r--r-- 1 root root  28961 Jun  7 12:13 dis.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 distutils
-rw-r--r-- 1 root root   6312 Jun  7 12:13 _distutils_system_mod.py
-rw-r--r-- 1 root root 105178 Jun  7 12:13 doctest.py
drwxr-xr-x 4 root root   4096 Aug 22 02:16 email
drwxr-xr-x 3 root root   4096 Aug 22 02:16 encodings
-rw-r--r-- 1 root root  79259 Jun  7 12:13 enum.py
-rw-r--r-- 1 root root    645 Jun  7 12:13 EXTERNALLY-MANAGED.original
-rw-r--r-- 1 root root  10178 Jun  7 12:13 filecmp.py
-rw-r--r-- 1 root root  15714 Jun  7 12:13 fileinput.py
-rw-r--r-- 1 root root   5999 Jun  7 12:13 fnmatch.py
-rw-r--r-- 1 root root  28667 Jun  7 12:13 fractions.py
-rw-r--r-- 1 root root  35496 Jun  7 12:13 ftplib.py
-rw-r--r-- 1 root root  38413 Jun  7 12:13 functools.py
-rw-r--r-- 1 root root   5218 Jun  7 12:13 __future__.py
-rw-r--r-- 1 root root   4975 Jun  7 12:13 genericpath.py
-rw-r--r-- 1 root root   7489 Jun  7 12:13 getopt.py
-rw-r--r-- 1 root root   5990 Jun  7 12:13 getpass.py
-rw-r--r-- 1 root root  21302 Jun  7 12:13 gettext.py
-rw-r--r-- 1 root root   8681 Jun  7 12:13 glob.py
-rw-r--r-- 1 root root   9656 Jun  7 12:13 graphlib.py
-rw-r--r-- 1 root root  24074 Jun  7 12:13 gzip.py
-rw-r--r-- 1 root root  11765 Jun  7 12:13 hashlib.py
-rw-r--r-- 1 root root  23024 Jun  7 12:13 heapq.py
-rw-r--r-- 1 root root    227 Jun  7 12:13 __hello__.py
-rw-r--r-- 1 root root   7717 Jun  7 12:13 hmac.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 html
drwxr-xr-x 3 root root   4096 Aug 22 02:16 http
-rw-r--r-- 1 root root  54865 Jun  7 12:13 imaplib.py
-rw-r--r-- 1 root root   3952 Jun  7 12:13 imghdr.py
drwxr-xr-x 5 root root   4096 Aug 22 02:16 importlib
-rw-r--r-- 1 root root  10606 Jun  7 12:13 imp.py
-rw-r--r-- 1 root root 124246 Jun  7 12:13 inspect.py
-rw-r--r-- 1 root root   4240 Jun  7 12:13 io.py
-rw-r--r-- 1 root root  75002 Jun  7 12:13 ipaddress.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 json
-rw-r--r-- 1 root root   1061 Jun  7 12:13 keyword.py
drwxr-xr-x 2 root root   4096 Aug 22 02:16 lib-dynload
-rw-r--r-- 1 root root  13936 Jun  7 12:13 LICENSE.txt
-rw-r--r-- 1 root root   5690 Jun  7 12:13 linecache.py
-rw-r--r-- 1 root root  79002 Jun  7 12:13 locale.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 logging
-rw-r--r-- 1 root root  13277 Jun  7 12:13 lzma.py
-rw-r--r-- 1 root root  78794 Jun  7 12:13 mailbox.py
-rw-r--r-- 1 root root   9369 Jun  7 12:13 mailcap.py
-rw-r--r-- 1 root root  14653 Jun  7 12:13 _markupbase.py
-rw-r--r-- 1 root root  22791 Jun  7 12:13 mimetypes.py
-rw-r--r-- 1 root root  23699 Jun  7 12:13 modulefinder.py
drwxr-xr-x 4 root root   4096 Aug 22 02:16 multiprocessing
-rw-r--r-- 1 root root   6929 Jun  7 12:13 netrc.py
-rw-r--r-- 1 root root  41087 Jun  7 12:13 nntplib.py
-rw-r--r-- 1 root root  29648 Jun  7 12:13 ntpath.py
-rw-r--r-- 1 root root   2887 Jun  7 12:13 nturl2path.py
-rw-r--r-- 1 root root  10348 Jun  7 12:13 numbers.py
-rw-r--r-- 1 root root  10447 Jun  7 12:13 opcode.py
-rw-r--r-- 1 root root  10965 Jun  7 12:13 operator.py
-rw-r--r-- 1 root root  60369 Jun  7 12:13 optparse.py
-rw-r--r-- 1 root root  39504 Jun  7 12:13 os.py
-rw-r--r-- 1 root root  21787 Jun  7 12:13 _osx_support.py
-rw-r--r-- 1 root root  48571 Jun  7 12:13 pathlib.py
-rwxr-xr-x 1 root root  63995 Jun  7 12:13 pdb.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 __phello__
-rw-r--r-- 1 root root  64949 Jun  7 12:13 pickle.py
-rw-r--r-- 1 root root  93486 Jun  7 12:13 pickletools.py
-rw-r--r-- 1 root root   8978 Jun  7 12:13 pipes.py
-rw-r--r-- 1 root root  24638 Jun  7 12:13 pkgutil.py
-rwxr-xr-x 1 root root  42273 Jun  7 12:13 platform.py
-rw-r--r-- 1 root root  28354 Jun  7 12:13 plistlib.py
-rw-r--r-- 1 root root  15198 Jun  7 12:13 poplib.py
-rw-r--r-- 1 root root  17013 Jun  7 12:13 posixpath.py
-rw-r--r-- 1 root root  24489 Jun  7 12:13 pprint.py
-rwxr-xr-x 1 root root  22883 Jun  7 12:13 profile.py
-rw-r--r-- 1 root root  29356 Jun  7 12:13 pstats.py
-rw-r--r-- 1 root root   6317 Jun  7 12:13 pty.py
-rw-r--r-- 1 root root   6189 Jun  7 12:13 _py_abc.py
drwxr-xr-x 2 root root  12288 Aug 22 02:16 __pycache__
-rw-r--r-- 1 root root  11396 Jun  7 12:13 pyclbr.py
-rw-r--r-- 1 root root   7878 Jun  7 12:13 py_compile.py
-rw-r--r-- 1 root root 229202 Jun  7 12:13 _pydecimal.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 pydoc_data
-rwxr-xr-x 1 root root 109130 Jun  7 12:13 pydoc.py
-rw-r--r-- 1 root root  94036 Jun  7 12:13 _pyio.py
-rw-r--r-- 1 root root  11496 Jun  7 12:13 queue.py
-rwxr-xr-x 1 root root   7267 Jun  7 12:13 quopri.py
-rw-r--r-- 1 root root  32162 Jun  7 12:13 random.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 re
-rw-r--r-- 1 root root   5437 Jun  7 12:13 reprlib.py
-rw-r--r-- 1 root root   7827 Jun  7 12:13 rlcompleter.py
-rw-r--r-- 1 root root  13159 Jun  7 12:13 runpy.py
-rw-r--r-- 1 root root   6351 Jun  7 12:13 sched.py
-rw-r--r-- 1 root root   2028 Jun  7 12:13 secrets.py
-rw-r--r-- 1 root root  19485 Jun  7 12:13 selectors.py
-rw-r--r-- 1 root root   8560 Jun  7 12:13 shelve.py
-rw-r--r-- 1 root root  13501 Jun  7 12:13 shlex.py
-rw-r--r-- 1 root root  55127 Jun  7 12:13 shutil.py
-rw-r--r-- 1 root root   2438 Jun  7 12:13 signal.py
-rw-r--r-- 1 root root   3128 Jun  7 12:13 _sitebuiltins.py
lrwxrwxrwx 1 root root     32 Jun  7 12:13 sitecustomize.py -> /etc/python3.11/sitecustomize.py
-rw-r--r-- 1 root root  23728 Jun  7 12:13 site.py
-rwxr-xr-x 1 root root  31162 Jun  7 12:13 smtpd.py
-rwxr-xr-x 1 root root  45418 Jun  7 12:13 smtplib.py
-rw-r--r-- 1 root root   7448 Jun  7 12:13 sndhdr.py
-rw-r--r-- 1 root root  37320 Jun  7 12:13 socket.py
-rw-r--r-- 1 root root  27586 Jun  7 12:13 socketserver.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 sqlite3
-rw-r--r-- 1 root root    231 Jun  7 12:13 sre_compile.py
-rw-r--r-- 1 root root    232 Jun  7 12:13 sre_constants.py
-rw-r--r-- 1 root root    229 Jun  7 12:13 sre_parse.py
-rw-r--r-- 1 root root  52207 Jun  7 12:13 ssl.py
-rw-r--r-- 1 root root  47705 Jun  7 12:13 statistics.py
-rw-r--r-- 1 root root   5485 Jun  7 12:13 stat.py
-rw-r--r-- 1 root root  12917 Jun  7 12:13 stringprep.py
-rw-r--r-- 1 root root  11786 Jun  7 12:13 string.py
-rw-r--r-- 1 root root  25277 Jun  7 12:13 _strptime.py
-rw-r--r-- 1 root root    257 Jun  7 12:13 struct.py
-rw-r--r-- 1 root root  88430 Jun  7 12:13 subprocess.py
-rw-r--r-- 1 root root  18480 Jun  7 12:13 sunau.py
-rw-r--r-- 1 root root  10368 Jun  7 12:13 symtable.py
lrwxrwxrwx 1 root root     35 Jun  7 12:13 _sysconfigdata__linux_x86_64-linux-gnu.py -> _sysconfigdata__x86_64-linux-gnu.py
-rw-r--r-- 1 root root  43375 Jun  7 12:13 _sysconfigdata__x86_64-linux-gnu.py
-rw-r--r-- 1 root root  32104 Jun  7 12:13 sysconfig.py
-rwxr-xr-x 1 root root  11299 Jun  7 12:13 tabnanny.py
-rwxr-xr-x 1 root root 105920 Jun  7 12:13 tarfile.py
-rw-r--r-- 1 root root  23301 Jun  7 12:13 telnetlib.py
-rw-r--r-- 1 root root  35207 Jun  7 12:13 tempfile.py
drwxr-xr-x 5 root root   4096 Aug 22 02:16 test
-rw-r--r-- 1 root root  19718 Jun  7 12:13 textwrap.py
-rw-r--r-- 1 root root   1003 Jun  7 12:13 this.py
-rw-r--r-- 1 root root   7220 Jun  7 12:13 _threading_local.py
-rw-r--r-- 1 root root  57818 Jun  7 12:13 threading.py
-rwxr-xr-x 1 root root  13495 Jun  7 12:13 timeit.py
-rw-r--r-- 1 root root  26336 Jun  7 12:13 tokenize.py
-rw-r--r-- 1 root root   2386 Jun  7 12:13 token.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 tomllib
-rw-r--r-- 1 root root  38574 Jun  7 12:13 traceback.py
-rw-r--r-- 1 root root  18047 Jun  7 12:13 tracemalloc.py
-rwxr-xr-x 1 root root  29215 Jun  7 12:13 trace.py
-rw-r--r-- 1 root root    879 Jun  7 12:13 tty.py
-rw-r--r-- 1 root root 144360 Jun  7 12:13 turtle.py
-rw-r--r-- 1 root root  10067 Jun  7 12:13 types.py
-rw-r--r-- 1 root root 118899 Jun  7 12:13 typing.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 unittest
drwxr-xr-x 3 root root   4096 Aug 22 02:16 urllib
-rw-r--r-- 1 root root  27597 Jun  7 12:13 uuid.py
-rwxr-xr-x 1 root root   7364 Jun  7 12:13 uu.py
drwxr-xr-x 4 root root   4096 Aug 22 02:16 venv
-rw-r--r-- 1 root root  21025 Jun  7 12:13 warnings.py
-rw-r--r-- 1 root root  21818 Jun  7 12:13 wave.py
-rw-r--r-- 1 root root  21513 Jun  7 12:13 weakref.py
-rw-r--r-- 1 root root   5893 Jun  7 12:13 _weakrefset.py
-rwxr-xr-x 1 root root  25090 Jun  7 12:13 webbrowser.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 wsgiref
-rw-r--r-- 1 root root   5977 Jun  7 12:13 xdrlib.py
drwxr-xr-x 7 root root   4096 Aug 22 02:16 xml
drwxr-xr-x 3 root root   4096 Aug 22 02:16 xmlrpc
-rw-r--r-- 1 root root   7535 Jun  7 12:13 zipapp.py
-rw-r--r-- 1 root root  92648 Jun  7 12:13 zipfile.py
-rw-r--r-- 1 root root  30897 Jun  7 12:13 zipimport.py
drwxr-xr-x 3 root root   4096 Aug 22 02:16 zoneinfo

my current solution is

mv /usr/lib/python3.11/sitecustomize    /usr/lib/python3/dist-packages

this way I won't leak into virtualenvs.
I don't understand why Ubuntu would ensist doing things this way.

@woutervh
Copy link
Collaborator Author

my usecases are triggered by ubuntu-based docker-images.
you can create a virtualenv and pip install sitecustomize-entrypoints, and pip/poetry will not complain.
but your entrypoints will not be triggered.

wondering what we can do on our side.

@woutervh
Copy link
Collaborator Author

wondering what we can do on our side.

let's start by packaging ubuntu's sitecustomize into an entrypoint:
https://github.com/libranet/sitecustomize-apport-hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants