Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use *.pth file instead of sitecustomize.py #4

Closed
ksamuel opened this issue Dec 27, 2019 · 9 comments
Closed

Use *.pth file instead of sitecustomize.py #4

ksamuel opened this issue Dec 27, 2019 · 9 comments

Comments

@ksamuel
Copy link

ksamuel commented Dec 27, 2019

The site-packages/sitecustomize.py file is not reliable loaded for everybody. To ensure pretty_errors is loaded after python -m pretty_errors, create a site-packages/pretty_errors.pth file containing:

import pretty_errors; pretty_errors.configure() # if you add option here, keep it on one line

If you don't want to use a *.pth, at least use /home/user/.local/lib/python3.7/site-packages/usercustomize.py, which is more likely to be imported and is meant for things like this. But *customize.py files are not imported in venv, which makes them pretty useless for real life Python usage.

@onelivesleft
Copy link
Owner

Can you link me to a simple venv setup I can use for testing?

@ksamuel
Copy link
Author

ksamuel commented Dec 28, 2019

You want me to upload a venv in github with a pth to show you how it works ?

@onelivesleft
Copy link
Owner

No, on second thought I almost have .pth working: when I upload it you can see if it meets your needs, and if it doesn't I'll look at setting up a venv.

@onelivesleft
Copy link
Owner

I've updated to 1.2.2, which allows you to use .pth files. I'm hoping that when it scans available install sites it finds the paths for venv. Check it out and let me know.

@ksamuel
Copy link
Author

ksamuel commented Dec 30, 2019

With 3.7 you'll get:

AttributeError:
module 'site' has no attribute 'getsitepackages'

getsitepackages() is not always available. Loop over sys.path and find the first entry containing 'site-packages'', it's probably your best bet.

@onelivesleft
Copy link
Owner

onelivesleft commented Dec 30, 2019

I'm on 3.7 and it works ok, as it does in 2.7, so there's something else up with that, though I can't guess what it could be. Looking at the source - https://github.com/python/cpython/blob/2.7/Lib/site.py - getsitepackages is in all the branches listed, from 3.5 up.

@ksamuel
Copy link
Author

ksamuel commented Dec 30, 2019

Either it's not in the virtualenv, or it's not in Python on some OS. Linux maintainers have the bad habits of changing such details.

@onelivesleft
Copy link
Owner

It's probably this: pypa/pipenv#3824

@ksamuel
Copy link
Author

ksamuel commented Dec 30, 2019

Something similar yes, as I'm not using pipenv but the bug seems exactly the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants