@@ -254,6 +254,7 @@ class StartupState:
254254 '_path_entries' ,
255255 '_importexecs' ,
256256 '_entrypoints' ,
257+ '_sitedir' ,
257258 )
258259
259260 def __init__ (self , known_paths = None ):
@@ -286,6 +287,7 @@ def __init__(self, known_paths=None):
286287 # when an entry fails.
287288 self ._importexecs = {}
288289 self ._entrypoints = {}
290+ self ._sitedir = None
289291
290292 def addsitedir (self , sitedir ):
291293 """Add a site directory and accumulate its .pth and .start startup data.
@@ -397,6 +399,8 @@ def _read_pth_file(self, sitedir, name):
397399 accepted paths are added to it so that subsequent .pth files in
398400 the same batch don't add them more than once.
399401 """
402+ self ._sitedir = sitedir
403+
400404 lines , filename = _read_pthstart_file (sitedir , name , ".pth" )
401405 if lines is None :
402406 return
@@ -500,6 +504,11 @@ def _extend_syspath(self):
500504 )
501505
502506 def _exec_imports (self ):
507+ # Inject 'sitedir' local variable in the current frame for
508+ # compatibility with Python 3.14. Especially, "-nspkg.pth" files
509+ # generated by setuptools use: sys._getframe(1).f_locals['sitedir'].
510+ sitedir = self ._sitedir
511+
503512 # For each `import` line we've seen in a .pth file, exec() it in
504513 # order, unless the .pth has a matching .start file in this same
505514 # batch. In that case, PEP 829 says the import lines are
0 commit comments