Describe the bug
sys.path different when running code through coverage
To Reproduce
How can we reproduce the problem?
Run a source file through symlink.
Answer the questions below:
- What version of Python are you using?
3.11
- What version of coverage.py shows the problem? The output of
coverage debug sys is helpful.
-- sys -------------------------------------------------------
coverage_version: 7.13.5
coverage_module: /usr/lib64/python3.11/site-packages/coverage/init.py
core: -none-
CTracer: available from /usr/lib64/python3.11/site-packages/coverage/tracer.cpython-311-x86_64-linux-gnu.so
plugins.file_tracers: -none-
plugins.configurers: -none-
plugins.context_switchers: -none-
configs_attempted: /home/hramrach/kbuild/.coveragerc
/home/hramrach/kbuild/.coveragerc.toml
/home/hramrach/kbuild/setup.cfg
/home/hramrach/kbuild/tox.ini
/home/hramrach/kbuild/pyproject.toml
configs_read: -none-
config_file: None
config_contents: -none-
data_file: -none-
python: 3.11.14 (main, Feb 13 2026, 01:31:07) [GCC]
platform: Linux-6.12.0-160000.26-rt-x86_64-with-glibc2.40
implementation: CPython
build: ('main', 'Feb 13 2026 01:31:07')
gil_enabled: True
executable: /usr/bin/python3.11
pth_files: /usr/lib64/python3.11/site-packages/a1_coverage.pth
def_encoding: utf-8
fs_encoding: utf-8
pid: 3047763
cwd: /home/hramrach/kbuild
path: /usr/bin
/usr/lib64/python311.zip
/usr/lib64/python3.11
/usr/lib64/python3.11/lib-dynload
/home/hramrach/.local/lib/python3.11/site-packages
editable.kicad_footprint_generator-1.1.2.finder.path_hook
/usr/lib64/python3.11/site-packages
/usr/lib64/python3.11/_import_failed
/usr/lib/python3.11/site-packages
environment: HOME = /home/hramrach
command_line: /usr/bin/coverage-3.11 debug sys
time: 2026-04-17 12:17:50
- What versions of what packages do you have installed? The output of
pip freeze is helpful.
aioesphomeapi==24.6.2
aiohappyeyeballs==2.4.4
aioquic==1.2.0
ajsonrpc==1.2.0
asgiref==3.8.1
asteval==1.0.6
async_interrupt==1.2.0
bitarray==3.0.0
bitstring==4.3.0
blinker==1.9.0
bottle==0.13.2
cached-property==2.0.1
certifi==2026.2.25
cffi==2.0.0
chacha20poly1305-reuseable==0.13.2
charset-normalizer==3.4.4
click==8.1.7
coverage==7.13.5
cryptography==43.0.0
cssselect==1.2.0
defcon==0.10.3
dukpy==0.3
ecdsa==0.19.0
esphome==2024.12.2
esphome-dashboard==20241217.1
esptool==4.7.0
feedparser==6.0.11
Flask==3.1.0
freetype-py==2.5.1
future==1.0.0
gflanguages==0.7.1
glyphsets==1.0.0
glyphsLib==6.9.5
hatchling==1.29.0
html5-parser==0.4.12
icmplib==3.0.4
idna==3.11
ifaddr==0.2.0
intelhex==2.3.0
itsdangerous==2.2.0
Jinja2==3.1.6
kaitaistruct==0.10
kconfiglib==13.7.1
-e git+https://gitlab.com/kicad/libraries/kicad-footprint-generator.git@01422a10f9e5bfa8fe8ae3b9ab0ab0d75dd555c6#egg=kicad_footprint_generator
ldap3==2.9.1
loguru==0.7.0
lxml==5.4.0
lxml-html-clean==0.4.2
MarkupSafe==3.0.2
marshmallow==3.23.2
mitmproxy==11.0.2
mitmproxy_rs==0.10.7
mobi==0.3.3
multivolumefile==0.2.3
mypy==1.10.0
mypy-extensions==1.0.0
noiseprotocol==0.3.1
numpy-stl==3.2.0
openstep_plist==0.4.0
packaging==26.0
paho-mqtt==1.6.1
passlib==1.7.4
pathspec==1.0.4
pillow==10.4.0
platformio==6.1.16
pluggy==1.6.0
protobuf==3.20.3
publicsuffix2==2.20191221
puremagic==1.27
pyasn1==0.6.1
pyasn1_modules==0.4.2
pychm==0.8.6
pycparser==2.21
pycryptodome==3.22.0
pyelftools==0.31
pygit2==1.19.1
pylsqpack==0.3.22
pyOpenSSL==24.3.0
pyperclip==1.9.0
pyppmd==1.2.0
pyserial==3.5
python-augeas==1.2.0
python-ldap==3.4.4
python-utils==3.9.1
PyYAML==6.0.2
pyzstd==0.16.2
reedsolo==1.7.0
requests==2.32.5
rpm==4.20.1
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.12
semantic-version==2.10.0
service-identity==24.2.0
sgmllib3k==1.0.0
sortedcontainers==2.4.0
starlette==0.39.2
tabulate==0.9.0
texttable==1.7.0
tomli==2.4.1
tornado==6.4.2
trove-classifiers==2026.1.14.14
typing_extensions==4.12.1
tzdata==2024.2
tzlocal==5.2
ufoLib2==0.17.0
unicodedata2==15.1.0
urllib3==2.6.3
urwid==2.6.16
uvicorn==0.30.6
voluptuous==0.14.2
Werkzeug==3.1.3
wsproto==1.2.0
zeroconf==0.132.2
zstandard==0.23.0
- What code shows the problem? Give us a specific commit of a specific repo that we can check out. If you've already worked around the problem, please provide a commit before that fix.
#!/usr/bin/python3.11 -s
import sys
print(sys.path)
exit(0)
- What commands should we run to reproduce the problem? Be specific. Include everything, even
git clone, pip install, and so on. Explain like we're five!
mkdir dir1
cat >dir1/script <<EOF
#!/usr/bin/python3.11 -s
import sys
print(sys.path)
exit(0)
EOF
mkdir dir2
ln -s ../dir1/script dir2
python3.11 dir2/script
['/home/hramrach/kbuild/dir1', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/home/hramrach/.local/lib/python3.11/site-packages', 'editable.kicad_footprint_generator-1.1.2.finder.path_hook', '/usr/lib64/python3.11/site-packages', '/usr/lib64/python3.11/_import_failed', '/usr/lib/python3.11/site-packages']
coverage run dir2/script
['/home/hramrach/kbuild/dir2', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/home/hramrach/.local/lib/python3.11/site-packages', 'editable.kicad_footprint_generator-1.1.2.finder.path_hook', '/usr/lib64/python3.11/site-packages', '/usr/lib64/python3.11/_import_failed', '/usr/lib/python3.11/site-packages']
Expected behavior
sys.path is the same regardless of running through python interpreter or coverage
In particular local libraries should be imported correctly.
Describe the bug
sys.path different when running code through coverage
To Reproduce
How can we reproduce the problem?
Run a source file through symlink.
Answer the questions below:
3.11
coverage debug sysis helpful.-- sys -------------------------------------------------------
coverage_version: 7.13.5
coverage_module: /usr/lib64/python3.11/site-packages/coverage/init.py
core: -none-
CTracer: available from /usr/lib64/python3.11/site-packages/coverage/tracer.cpython-311-x86_64-linux-gnu.so
plugins.file_tracers: -none-
plugins.configurers: -none-
plugins.context_switchers: -none-
configs_attempted: /home/hramrach/kbuild/.coveragerc
/home/hramrach/kbuild/.coveragerc.toml
/home/hramrach/kbuild/setup.cfg
/home/hramrach/kbuild/tox.ini
/home/hramrach/kbuild/pyproject.toml
configs_read: -none-
config_file: None
config_contents: -none-
data_file: -none-
python: 3.11.14 (main, Feb 13 2026, 01:31:07) [GCC]
platform: Linux-6.12.0-160000.26-rt-x86_64-with-glibc2.40
implementation: CPython
build: ('main', 'Feb 13 2026 01:31:07')
gil_enabled: True
executable: /usr/bin/python3.11
pth_files: /usr/lib64/python3.11/site-packages/a1_coverage.pth
def_encoding: utf-8
fs_encoding: utf-8
pid: 3047763
cwd: /home/hramrach/kbuild
path: /usr/bin
/usr/lib64/python311.zip
/usr/lib64/python3.11
/usr/lib64/python3.11/lib-dynload
/home/hramrach/.local/lib/python3.11/site-packages
editable.kicad_footprint_generator-1.1.2.finder.path_hook
/usr/lib64/python3.11/site-packages
/usr/lib64/python3.11/_import_failed
/usr/lib/python3.11/site-packages
environment: HOME = /home/hramrach
command_line: /usr/bin/coverage-3.11 debug sys
time: 2026-04-17 12:17:50
pip freezeis helpful.aioesphomeapi==24.6.2
aiohappyeyeballs==2.4.4
aioquic==1.2.0
ajsonrpc==1.2.0
asgiref==3.8.1
asteval==1.0.6
async_interrupt==1.2.0
bitarray==3.0.0
bitstring==4.3.0
blinker==1.9.0
bottle==0.13.2
cached-property==2.0.1
certifi==2026.2.25
cffi==2.0.0
chacha20poly1305-reuseable==0.13.2
charset-normalizer==3.4.4
click==8.1.7
coverage==7.13.5
cryptography==43.0.0
cssselect==1.2.0
defcon==0.10.3
dukpy==0.3
ecdsa==0.19.0
esphome==2024.12.2
esphome-dashboard==20241217.1
esptool==4.7.0
feedparser==6.0.11
Flask==3.1.0
freetype-py==2.5.1
future==1.0.0
gflanguages==0.7.1
glyphsets==1.0.0
glyphsLib==6.9.5
hatchling==1.29.0
html5-parser==0.4.12
icmplib==3.0.4
idna==3.11
ifaddr==0.2.0
intelhex==2.3.0
itsdangerous==2.2.0
Jinja2==3.1.6
kaitaistruct==0.10
kconfiglib==13.7.1
-e git+https://gitlab.com/kicad/libraries/kicad-footprint-generator.git@01422a10f9e5bfa8fe8ae3b9ab0ab0d75dd555c6#egg=kicad_footprint_generator
ldap3==2.9.1
loguru==0.7.0
lxml==5.4.0
lxml-html-clean==0.4.2
MarkupSafe==3.0.2
marshmallow==3.23.2
mitmproxy==11.0.2
mitmproxy_rs==0.10.7
mobi==0.3.3
multivolumefile==0.2.3
mypy==1.10.0
mypy-extensions==1.0.0
noiseprotocol==0.3.1
numpy-stl==3.2.0
openstep_plist==0.4.0
packaging==26.0
paho-mqtt==1.6.1
passlib==1.7.4
pathspec==1.0.4
pillow==10.4.0
platformio==6.1.16
pluggy==1.6.0
protobuf==3.20.3
publicsuffix2==2.20191221
puremagic==1.27
pyasn1==0.6.1
pyasn1_modules==0.4.2
pychm==0.8.6
pycparser==2.21
pycryptodome==3.22.0
pyelftools==0.31
pygit2==1.19.1
pylsqpack==0.3.22
pyOpenSSL==24.3.0
pyperclip==1.9.0
pyppmd==1.2.0
pyserial==3.5
python-augeas==1.2.0
python-ldap==3.4.4
python-utils==3.9.1
PyYAML==6.0.2
pyzstd==0.16.2
reedsolo==1.7.0
requests==2.32.5
rpm==4.20.1
ruamel.yaml==0.18.6
ruamel.yaml.clib==0.2.12
semantic-version==2.10.0
service-identity==24.2.0
sgmllib3k==1.0.0
sortedcontainers==2.4.0
starlette==0.39.2
tabulate==0.9.0
texttable==1.7.0
tomli==2.4.1
tornado==6.4.2
trove-classifiers==2026.1.14.14
typing_extensions==4.12.1
tzdata==2024.2
tzlocal==5.2
ufoLib2==0.17.0
unicodedata2==15.1.0
urllib3==2.6.3
urwid==2.6.16
uvicorn==0.30.6
voluptuous==0.14.2
Werkzeug==3.1.3
wsproto==1.2.0
zeroconf==0.132.2
zstandard==0.23.0
git clone,pip install, and so on. Explain like we're five!mkdir dir1
cat >dir1/script <<EOF
#!/usr/bin/python3.11 -s
import sys
print(sys.path)
exit(0)
EOF
mkdir dir2
ln -s ../dir1/script dir2
python3.11 dir2/script
['/home/hramrach/kbuild/dir1', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/home/hramrach/.local/lib/python3.11/site-packages', 'editable.kicad_footprint_generator-1.1.2.finder.path_hook', '/usr/lib64/python3.11/site-packages', '/usr/lib64/python3.11/_import_failed', '/usr/lib/python3.11/site-packages']
coverage run dir2/script
['/home/hramrach/kbuild/dir2', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/home/hramrach/.local/lib/python3.11/site-packages', 'editable.kicad_footprint_generator-1.1.2.finder.path_hook', '/usr/lib64/python3.11/site-packages', '/usr/lib64/python3.11/_import_failed', '/usr/lib/python3.11/site-packages']
Expected behavior
sys.path is the same regardless of running through python interpreter or coverage
In particular local libraries should be imported correctly.