Installing Python Script, maintaining a reference to Python 2.6

I am trying to distribute my Python program. The program is based on version 2.6. I looked through the distribution documentation: http://docs.python.org/distutils/index.html , and so far I have realized that I basically need to write a setup.py script. Sort of:

setup(name='Distutils',
  version='1.0',
  description='Python Distribution Utilities',
  author='My Name',
  author_email='My Email',
  url='some URL',
  package_dir={'': 'src'},
  packages=[''],
 )

I would like to make sure that my program uses the 2.6 interpreter library when the user installs it on their box. What would be the best approach to ensure that my program uses 2.6? Should I redistribute the python 2.6 library along with my program? Is there an alternative approach?

+3
source share
2

, Python :

#! /usr/bin/env python2.6

- sys.version_info, :

if (sys.version_info[0] != 2) or (sys.version_info[1]<6):
    if sys.version_info[0] > 2:
        print("Version 2.6+, and not 3.0+ needed.")
        sys.exit(1)
    else:
        print "Version 2.6+, needed. Please upgrade Python."
        sys.exit(1)

-, , , , script "python2.6" ; :

  •  
  • UNIX- , . 
  • , Python2.7, Python 2.6.

"" Python script, "python2.6"... "python2.9", 2.6+ Python 3.0+. script , python, . script , , Python.

, Python:

def which(program):
    import os
    def is_exe(fpath):
        return os.path.exists(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None

def first_which(progs):
    for prog in progs:
        progloc = which(prog)
        if progloc != None:
            return progloc
    return None

def main():
    interpreter=first_which(["python2.6","python2.7","python2.8","python2.9"])
    # Invoke your program using "interpreter"
    # You will need to use os.popen or subprocess,
    # depending on the version of Python which which
    # this launcher script was invoked...

, , , -... Python , , Python ( ... ).

Python . , , Python. , .

+1

sys.hexversion , 0x02060000.

0

Source: https://habr.com/ru/post/1740535/


All Articles