How remove Tcl/Tk fom py2exe distribution?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Peuser

    How remove Tcl/Tk fom py2exe distribution?

    Hi,
    I should like to make a distribution (using Tkinter), with standard DLLs
    removed.

    pythonXX.dll is no problem.

    tcl und tk, which make the mass of mega bytes, cannot be removed because
    _tkinter.pyd seems to expect them in the same directory

    (Question 1) Is there a configration or path setting in py2exe/distutils I
    have overlooked?

    O.k. In fact I do not want to have _tkinter.dll either because it belongs to
    standard distribution
    The command line option --exclude Tkinter however leads to an error message
    when running the exe - this could have been expected however ;-)

    Now I changed
    import Tkinter
    to
    Tkinter= __import__("Tki nter")

    This worked fine sofar as --exclude Tkinter was no longer needed to prevent
    py2exe from copying tcl/tk

    However "Tkinter" was not found by imputils now...

    (Question 2) What did I miss??

    Kindly
    Michael P


  • Graham Fawcett

    #2
    Re: How remove Tcl/Tk fom py2exe distribution?

    Michael Peuser wrote:
    [color=blue]
    >Hi,
    >I should like to make a distribution (using Tkinter), with standard DLLs
    >removed.
    >
    >pythonXX.dll is no problem.
    >
    >tcl und tk, which make the mass of mega bytes, cannot be removed because
    >_tkinter.pyd seems to expect them in the same directory
    >
    >(Question 1) Is there a configration or path setting in py2exe/distutils I
    >have overlooked?
    >
    >O.k. In fact I do not want to have _tkinter.dll either because it belongs to
    >standard distribution
    >The command line option --exclude Tkinter however leads to an error message
    >when running the exe - this could have been expected however ;-)
    >
    >[/color]

    It's a bit unclear, Michael, what you're trying to accomplish. On the
    one hand, you're using py2exe to deploy your application, which suggests
    that you don't expect your users to have a Python distribution on their
    computers. On the other hand, you're looking to deploy a Tkinter app,
    but without any tcl/tk files, because they "belong to the standard
    distribution", suggesting that you *do* expect your users to have a
    Python distribution.

    If you can assume that your clients have a standard distribution on
    their machines, don't use py2exe. It's the wrong tool for the job.

    In case I'm missing something: you could always, as part of your build,
    just delete files from the py2exe-generated build directory. For
    example, at the end of your setup.py script, add some lines to delete
    the tk/tcl files from your build path. I've used this "strategy"
    sometimes when building py2exe apps that use the Python Imaging Library.
    (PIL has tcl/tk import dependencies, but doesn't actually need tcl/tk
    for the majority of its functions.)

    -- Graham


    Comment

    • Michael Peuser

      #3
      Re: How remove Tcl/Tk fom py2exe distribution?

      Hi Graham - thnak you for your answer!

      "Graham Fawcett" <fawcett@teksav vy.com> schrieb im Newsbeitrag
      news:mailman.10 61014105.16562. [email protected] ...[color=blue]
      > Michael Peuser wrote:
      >[color=green]
      > >Hi,
      > >I should like to make a distribution (using Tkinter), with standard DLLs
      > >removed.[/color][/color]
      [..details in first posting ...][color=blue]
      >
      > It's a bit unclear, Michael, what you're trying to accomplish. On the
      > one hand, you're using py2exe to deploy your application, which suggests
      > that you don't expect your users to have a Python distribution on their
      > computers. On the other hand, you're looking to deploy a Tkinter app,
      > but without any tcl/tk files, because they "belong to the standard
      > distribution", suggesting that you *do* expect your users to have a
      > Python distribution.[/color]


      It is more difficult:
      I *can* request the potiential user to install a "standard" Python of a
      given version, but not more! And by no means do I want to interfere with his
      or her installation. This means *everything* except minimal Python
      (includingTcl/Tk) must be packed somehow.....

      The program shall not be *installed* but run from a double click!

      Only on special request I can deliver thePython-, Tcl-, Tk- dlls and this
      phantastic Tcl folder with megabytes of chinese character sets....

      But I mostly want to reduce the size of the distribution, especially in
      upgrade and bug-fix situations.
      [color=blue]
      > In case I'm missing something: you could always, as part of your build,
      > just delete files from the py2exe-generated build directory. For
      > example, at the end of your setup.py script, add some lines to delete
      > the tk/tcl files from your build path. I've used this "strategy"
      > sometimes when building py2exe apps that use the Python Imaging Library.
      > (PIL has tcl/tk import dependencies, but doesn't actually need tcl/tk
      > for the majority of its functions.)
      >
      > -- Graham
      >[/color]

      I tried this! This will not help, because - in this case - Tkinter *is*
      used. The importer just does not find it (probably because py2exe modifies
      its behaviour....

      This is why I use

      Tkinter= __import__("Tki nter")

      But this does not wort either...

      Kindly Michael P[color=blue]
      >[/color]


      Comment

      • Thomas Heller

        #4
        Re: How remove Tcl/Tk fom py2exe distribution?

        "Michael Peuser" <[email protected] > writes:
        [color=blue][color=green]
        >> In case I'm missing something: you could always, as part of your
        >> build, just delete files from the py2exe-generated build
        >> directory. For example, at the end of your setup.py script, add some
        >> lines to delete the tk/tcl files from your build path. I've used
        >> this "strategy" sometimes when building py2exe apps that use the
        >> Python Imaging Library. (PIL has tcl/tk import dependencies, but
        >> doesn't actually need tcl/tk for the majority of its functions.)[/color][/color]

        IMO --exclude Tkinter should also work.
        [color=blue]
        >
        > I tried this! This will not help, because - in this case - Tkinter *is*
        > used. The importer just does not find it (probably because py2exe modifies
        > its behaviour....
        >
        > This is why I use
        >
        > Tkinter= __import__("Tki nter")
        >
        > But this does not wort either...[/color]

        Ok. First you should make sure that Tkinter is not found and copied by
        py2exe. The '--exclude' flag could be used, or the above __import__
        trick.

        Then, you should make sure that your executable finds the 'standard'
        Tkinter module (and tcl/tk) installation by including the proper
        directory into sys.path. Normally py2exe takes some care to *not* find
        modules or packages from a Python installation on the system.

        A little experimentation is probably needed, and hacking py2exe could
        maybe help. You can change this code (in py2exe\build_ex e.py, near line
        926)
        header = struct.pack("<i ii",
        self.optimize, # optimize
        0, # verbose
        0x0bad3bad,
        )
        into this
        header = struct.pack("<i ii",
        self.optimize, # optimize
        1, # verbose
        0x0bad3bad,
        )
        and the resulting executable will trace import statements.

        Thomas

        Comment

        • Michael Peuser

          #5
          Re: How remove Tcl/Tk fom py2exe distribution?

          Thank you Thomas, for these excellent advice. "verbose" of course just
          supports debugging and does not prevent py2exe from beeing quite autistic.
          And it does a good job in that: Not only sys.path but sys.prefix as well as
          sys.exec_prefix are faked to the local directory. This makes it a little bit
          harder to supplement the path info.

          Tcl also has the nasty habbit to look arround according to sys.prefix
          settings and trying this and that....

          Nevertheless I think I can do the next step. It could be of help, if py2exe
          either
          - could become configurable (i.e. optionally leave the os variables as they
          are)
          or
          - make them somewhere available

          KIndly
          Michael P


          "Thomas Heller" <theller@python .net> schrieb im Newsbeitrag
          news:7k5dzwo9.f [email protected].. .

          [color=blue]
          > Ok. First you should make sure that Tkinter is not found and copied by
          > py2exe. The '--exclude' flag could be used, or the above __import__
          > trick.
          >
          > Then, you should make sure that your executable finds the 'standard'
          > Tkinter module (and tcl/tk) installation by including the proper
          > directory into sys.path. Normally py2exe takes some care to *not* find
          > modules or packages from a Python installation on the system.
          >
          > A little experimentation is probably needed, and hacking py2exe could
          > maybe help. You can change this code (in py2exe\build_ex e.py, near line
          > 926)
          > header = struct.pack("<i ii",
          > self.optimize, # optimize
          > 0, # verbose
          > 0x0bad3bad,
          > )
          > into this
          > header = struct.pack("<i ii",
          > self.optimize, # optimize
          > 1, # verbose
          > 0x0bad3bad,
          > )
          > and the resulting executable will trace import statements.
          >
          > Thomas[/color]


          Comment

          • Michael Peuser

            #6
            Re: How remove Tcl/Tk fom py2exe distribution?


            "Michael Peuser" <[email protected] > schrieb im Newsbeitrag
            news:bhl73o$745 [email protected]...[color=blue]
            > Thank you Thomas, for these excellent advice. "verbose" of course just
            > supports debugging and does not prevent py2exe from beeing quite autistic.
            > And it does a good job in that: Not only sys.path but sys.prefix as well[/color]
            as[color=blue]
            > sys.exec_prefix are faked to the local directory. This makes it a little[/color]
            bit[color=blue]
            > harder to supplement the path info.[/color]


            Well not *as* much. Because I am using win32api anyhow, it was easy to paste
            CheckPythonPath s from regcheck.py
            Kindly
            Michael P


            Comment

            Working...