[Bug 1971637] [NEW] sitecustomize.py not imported in a virtual environment

Роман Донченко 1971637 at bugs.launchpad.net
Wed May 4 23:23:40 UTC 2022


Public bug reported:

This is on Ubuntu 22.04, python3==3.10.4-3.

Run this:

$ python3.10 -mvenv ./venv
$ echo 'print("In sitecustomize.py")' > ./venv/lib/python3.10/site-packages/sitecustomize.py
$ ./venv/bin/python -c ''
[nothing]

Expected output:

In sitecustomize.py


The reason this doesn't work is that the python3 package contains its own sitecustomize module (at /usr/lib/python3.10/sitecustomize.py) whose job is to initialize the Apport exception hook, and /usr/lib/python3.10 is listed before ./venv/lib/python3.10/site-packages in the default sys.path.

I think the best way to fix this would be to:

1. Remove /usr/lib/python3.10/sitecustomize.py from
libpython3.10-minimal

2. Add /usr/lib/python3/dist-packages/apport.pth with the following
contents to python3-apport:

   import apport_python_hook; apport_python_hook.install()

This would have the same effect as the current sitecustomize.py, but
would not conflict with user-provided sitecustomize modules.

Alternatively, /usr/lib/python3.10/sitecustomize.py could simply be
moved to /usr/lib/python3.10/dist-packages, which would also fix the
problem. A disadvantage of this approach is that a user-defined
/usr/local/lib/python3.10/dist-packages/sitecustomize.py file would
override it and disable the Apport hook.

** Affects: python3.10 (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to python3.10 in Ubuntu.
https://bugs.launchpad.net/bugs/1971637

Title:
  sitecustomize.py not imported in a virtual environment

Status in python3.10 package in Ubuntu:
  New

Bug description:
  This is on Ubuntu 22.04, python3==3.10.4-3.

  Run this:

  $ python3.10 -mvenv ./venv
  $ echo 'print("In sitecustomize.py")' > ./venv/lib/python3.10/site-packages/sitecustomize.py
  $ ./venv/bin/python -c ''
  [nothing]

  Expected output:

  In sitecustomize.py

  
  The reason this doesn't work is that the python3 package contains its own sitecustomize module (at /usr/lib/python3.10/sitecustomize.py) whose job is to initialize the Apport exception hook, and /usr/lib/python3.10 is listed before ./venv/lib/python3.10/site-packages in the default sys.path.

  I think the best way to fix this would be to:

  1. Remove /usr/lib/python3.10/sitecustomize.py from
  libpython3.10-minimal

  2. Add /usr/lib/python3/dist-packages/apport.pth with the following
  contents to python3-apport:

     import apport_python_hook; apport_python_hook.install()

  This would have the same effect as the current sitecustomize.py, but
  would not conflict with user-provided sitecustomize modules.

  Alternatively, /usr/lib/python3.10/sitecustomize.py could simply be
  moved to /usr/lib/python3.10/dist-packages, which would also fix the
  problem. A disadvantage of this approach is that a user-defined
  /usr/local/lib/python3.10/dist-packages/sitecustomize.py file would
  override it and disable the Apport hook.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/python3.10/+bug/1971637/+subscriptions




More information about the foundations-bugs mailing list