Opened 5 years ago

Closed 5 years ago

Last modified 6 months ago

#20027 closed Bug (wontfix) shebang should reflect used python executable

Reported by: anonymous Owned by: nobody
Component: Python 3 Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


since Django now supports both Python 2 and Python 3, it seems that shebang in generated in new projects should reflect this. Currently, always points to "python", but IMHO when generated with python3, it should point to "python3". I think it makes sense to manage a project with python version that was used to generate it.

Change History (6)

comment:1 Changed 5 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

There isn't any guarantee that the executables for Python 2 and 3 are called python and python3. They may just as well be called python2 and python.

comment:2 Changed 5 years ago by anonymous

Right, so what about using the name of the binary that was used? As in sys.executable.

comment:3 Changed 5 years ago by Aymeric Augustin

If you're going to share the code — either because it's open source, or with co-workers — this could still be a problem. (Rewriting sheebangs always causes trouble.)

The recommended way to deal with this is to create a virtualenv with the Python binary you want, and to activate it whenever your work on your Django project.

comment:4 Changed 2 years ago by Raphaël Hertzog

What about rewriting it at least when "python" does not exist on the PATH?

When I wrote a test suite for the Debian package, I tested specifically in a Python3 only environment (and in Debian, much like most sane distros, Python 3 is /usr/bin/python3) and I was astonished that django-admin startproject would not create a working ./

Last edited 2 years ago by Raphaël Hertzog (previous) (diff)

comment:5 Changed 2 years ago by Collin Anderson

I expect this will become more of an issue soon when people start using Ubuntu 16.04, which doesn't have /usr/bin/python installed by default. It basically means Django won't work outside of a virtualenv unless you manually change

os.path.basename(sys.executable) seems reasonable to me.

Or, we could hard code it as python3 and and tell people to change it by hand if they really want to start a new project using python 2. :)

Or just wait til January when we remove py2 support anyway.

comment:6 Changed 6 months ago by bhch

setuptools automatically replaces the shebang line with the interpreter being used. For example, if you install Django in a virtualenv, the shebang gets re-written from this - #!/usr/bin/env python to this - #!/path/to/venv/bin/python. So why hardcode the shebang when all works perfectly anyway?

Note: See TracTickets for help on using tickets.
Back to Top