This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: ImpImporter.find_modules removes symlinks in paths
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, cryvate
Priority: normal Keywords: patch

Created on 2017-12-01 00:10 by cryvate, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 4672 open Cryvate, 2017-12-01 23:18
Messages (3)
msg307353 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2017-12-01 00:10
ImpImporter.find_modules calls os.path.real on the path used:

This means if there is a submodule ( which first appears on the path involving a symlink that


has the path with the symlinks removed whereas

import foo

does have the symlinks. Note that is in the absence of any PEP302 import hooks.

This behaviour comes up in pytest test/plugin collection in virtual environments in Py2.7 on linux where they have a symlinked venv/local/lib before venv/lib on the path and creates problems.

There might very well be a good reason the path is made absolute here, however the test suite passes when it is reverted to path = [self.path].
msg307385 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2017-12-01 12:45
Ignoring testing code, there is minimal use of os.path.realpath in the stdlib (

- Lib/ used before opening a file (works around a cygwin bug)
- Lib/unittest/ used to compare two paths for equality
- Lib/ as outlined in this issue
- Lib/ used to determine the directory
- Lib/ path and realpath added to caching dictionary

So the question that remains is whether __import__ does this on the hood? I get not due to the difference noted in the OP betweein importing and using pkgutil.
msg307411 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2017-12-01 20:52
Import itself I don't believe calls os.path.realpath(), so this is probably just something pkgutil happens to do.
Date User Action Args
2022-04-11 14:58:55adminsetgithub: 76369
2017-12-01 23:18:47Cryvatesetkeywords: + patch
stage: patch review
pull_requests: + pull_request4580
2017-12-01 20:52:39brett.cannonsetnosy: + brett.cannon
messages: + msg307411
2017-12-01 12:45:07cryvatesetmessages: + msg307385
2017-12-01 00:10:50cryvatecreate