Coder Social home page Coder Social logo

Python 3.11 and above adding default module search path from the “PythonPath” registry key if the standard library was found already about cpython HOT 4 OPEN

tanzim avatar tanzim commented on July 17, 2024
Python 3.11 and above adding default module search path from the “PythonPath” registry key if the standard library was found already

from cpython.

Comments (4)

tanzim avatar tanzim commented on July 17, 2024 1

The more important bug (perhaps already filed separately?) is import site in a ._pth file also including user site packages. The only reasonable workaround is to add sys.path.append(site.getusersitepackages()) but it seems fairly reasonable given the context.

I haven't raised a separate issue for this but sounds like I should. I'll also send a patch alongside.

Edit. Raised #120037

from cpython.

tanzim avatar tanzim commented on July 17, 2024

The most relevant part of the discussion that relates to this bug:

It seems you uncovered a bug in “Modules/getpath.py”. It’s not supposed to add the default module search path from the “PythonPath” registry key if the standard library was found already. However, the code is only checking the variables home and stdlib_dir, which aren’t set if the standard library was found in a zip file such as “python311.zip”. A variable needs to be defined when the standard library was found as a zip file, which can be included in the check that determines whether to fetch the default search path from the registry.

from cpython.

zooba avatar zooba commented on July 17, 2024

It looks like your entire workaround is to add the path you do want into sys.path (i.e. keep the ._pth file), rather than trying to remove the ones you don't want.

Personally, I really dislike the reliance on registry keys for finding the install. Unfortunately, it broke too many people to turn it off (i.e. don't install the default keys). I seem to recall that we also broke people when we accidentally turned it off in an earlier version of 3.11.

In any case, getpath.py is much easier to change than before. Anyone is welcome to submit a PR. If the detection is clear enough, we can probably backport the fix to maintenance releases.

The more important bug (perhaps already filed separately?) is import site in a ._pth file also including user site packages. The only reasonable workaround is to add sys.path.append(site.getusersitepackages()) but it seems fairly reasonable given the context.

from cpython.

zooba avatar zooba commented on July 17, 2024

I'll also send a patch alongside.

I don't think you've contributed before? The basic idea is to send a PR against main and then we'll worry about backporting it to earlier releases. There's more info at devguide.python.org.

The changes for this one should be entirely in Modules/getpath.py. The other is probably a bit more complex - I don't remember whether the flag for no user site packages can be set from getpath.py.

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.