Is there a standard way to make sure a python script will be interpreted by python2 and not python3?

前端 未结 8 1063
旧时难觅i
旧时难觅i 2020-12-31 00:56

Is there a standard way to make sure a python script will be interpreted by python2 and not python3? On my distro, I can use #!/usr/bin/env python2 as the shebang, but it se

8条回答
  •  余生分开走
    2020-12-31 01:49

    Depends on how you're distributing it, I guess.

    If you're using a normal setup.py file to manage your distribution, have it bomb out if the user is trying to install it in Python 3.

    Once it's installed, the shebang of the console script created by (say) setuptools will likely be linked to the specific interpreter used to install it.

    If you're doing something weird for your installation, you can in whatever installation script you're using look for python interpreters and store a choice. You might first check whether whatever is called "python" is a 2.x. If not, check for "python2.7", "python2.6", etc to see what's available.

提交回复
热议问题