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

wrong shebang line for script installed within python script on OSX, python3 #620

Closed
matthew-brett opened this issue Jun 18, 2014 · 2 comments

Comments

@matthew-brett
Copy link

Sorry for the verbose title.

I'm installing using the waf build tool, and ran into this problem with incorrect shebang lines for installed scripts.

The following script makes a virtualenv, writes a trivial package with a script, and installs it into the virtualenv. The output shows that the shebang line has incorrectly picked up the python from which the script is run, rather than the virtualenv python:

from os.path import join as pjoin, abspath
from subprocess import check_output

# Make virtualenv
check_output(['virtualenv', 'venv'])
# Write a tiny package
with open('setup.py', 'wt') as fobj:
    fobj.write(
"""from distutils.core import setup
setup(scripts = ['test_script'])
""")
with open('test_script', 'wt') as fobj:
    fobj.write(
"""#!python
print("Something")
""")

# Install package into virtualenv
venv_bin = pjoin(abspath('venv'), 'bin')
venv_python = pjoin(venv_bin, 'python')
check_output([venv_python, 'setup.py', 'install'])
# Show result of shebang rewrite
with open(pjoin(venv_bin, 'test_script'), 'rt') as fobj:
    print(fobj.read())

Running with Python 3:

$ python3 run_script.py 
#!/Library/Frameworks/Python.framework/Versions/3.4/bin/python3
print("Something")

The result should be something like:

#!/Users/me/venv_test/venv/bin/python
print("Something")

that is, the shebang line should come from the virtualenv not the python running the script.

Running the same script with Python2 gives the correct shebang line.
Running the script in Linux gives the correct line.
I've tested with 1.11.6 and current develop branch.

Possibly related to gh-532 in that it concerns shebang lines, OSX and Python 3.

@matthew-brett
Copy link
Author

This seems to be an interaction between the Python running virtualenv and the Python from --python=. For example, if I change the script above thus:

# Make virtualenv
check_output(['virtualenv', '--python=/usr/bin/python', 'venv'])

then I get the expected output. Similarly if I install virtualenv into system (2.7) Python instead and change the lines above to:

# Make virtualenv - now with virtualenv running against 2.7
check_output(['virtualenv', '--python=/usr/local/bin/python3.4', 'venv'])

then I get the expected (correct) output again.

@stale
Copy link

stale bot commented Jan 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Just add a comment if you want to keep it open. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 15, 2019
@stale stale bot closed this as completed Jan 22, 2019
@pypa pypa locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant