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

sys.orig_argv is not original, at least on some systems #125006

Open
pkit opened this issue Oct 5, 2024 · 2 comments
Open

sys.orig_argv is not original, at least on some systems #125006

pkit opened this issue Oct 5, 2024 · 2 comments

Comments

@pkit
Copy link

pkit commented Oct 5, 2024

In an OSX .venv the "original" sys.orig_argv is not really original...

(.venv) % cat orig.py
import sys

print(sys.orig_argv)

(.venv) % python orig.py 
['/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python', 'orig.py']

(.venv) % which python
/Users/user/git/project/.venv/bin/python

I can use os.environ["_"] but it's a workaround.

@vstinner
Copy link
Member

vstinner commented Oct 5, 2024

I cannot reproduce the issue on Linux.

$ python3 -m venv env
$ env/bin/python -c 'import sys; print(sys.orig_argv[0])'
env/bin/python

$ source env/bin/activate
(env) $ python -c 'import sys; print(sys.orig_argv[0])'
python

(env) $ which python
~/env/bin/python
(env) $ ls -l env/bin/python
lrwxrwxrwx 1 vstinner vstinner 7  5 oct.  22:31 env/bin/python -> python3*
(env) $ ls -l env/bin/python3
lrwxrwxrwx 1 vstinner vstinner 16  5 oct.  22:31 env/bin/python3 -> /usr/bin/python3*

You can also have a look at:

(env) vstinner@mona$ python
>>> import sys
>>> sys.executable
'/home/vstinner/env/bin/python'
>>> sys._base_executable
'/usr/bin/python3.12'

@pkit
Copy link
Author

pkit commented Oct 5, 2024

Yup. As I've said it's probably OSX-specific

This one is inside venv:

% python -c 'import sys; print(sys.orig_argv[0])'
/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/Resources/Python.app/Contents/MacOS/Python
% python -c 'import sys; print(sys.executable, sys._base_executable)'
/Users/user/git/project/.venv/bin/python /opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/bin/python3.11

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