How remove Tcl/Tk fom py2exe distribution?

M

Michael Peuser

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__("Tkinter")

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
 
G

Graham Fawcett

Michael said:
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 ;-)

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
 
M

Michael Peuser

Hi Graham - thnak you for your answer!

[..details in first posting ...]
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.


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.
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

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__("Tkinter")

But this does not wort either...

Kindly Michael P
 
T

Thomas Heller

IMO --exclude Tkinter should also work.
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__("Tkinter")

But this does not wort either...

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_exe.py, near line
926)
header = struct.pack("<iii",
self.optimize, # optimize
0, # verbose
0x0bad3bad,
)
into this
header = struct.pack("<iii",
self.optimize, # optimize
1, # verbose
0x0bad3bad,
)
and the resulting executable will trace import statements.

Thomas
 
M

Michael Peuser

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
 
M

Michael Peuser

Michael Peuser said:
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.


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,220
Latest member
AugustinaJ

Latest Threads

Top