Opened 4 years ago

Closed 4 years ago

Last modified 11 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 (5)

comment:1 Changed 4 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 4 years ago by anonymous

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

comment:3 Changed 4 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 11 months 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 11 months ago by Raphaël Hertzog (previous) (diff)

comment:5 Changed 11 months 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.

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