![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() ![]() |
A py2exe solution
It hasn't been much of a problem, I'm guessing mainly because people have found a simple solution around it. But instead ColdDeath coded a solution for me.
The problem was when py2exe compiles it's programs, it outputs like so: Your Directory - build - dist - - program - - - program.exe Which means every client will need to open up "Your Directory/dist/program/program.exe". Not very convenient. With this simple C++ program at: http://1v7.com/drsane/py2exe_solution.zip, #include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main(int argc, char **argv)
{
char direct_ini_contents[1024]; /* declare file string */
char cwd[1024]; /* declare cwd string */
char fileName[1024]; /* declare filename string */
ifstream the_file ("redirect.ini"); /* open file */
the_file >> direct_ini_contents; /* send contents of file to string */
the_file.close(); /* close file object */
cwd[0] = system("cd"); /* set cwd to the cwd string */
sprintf(fileName, "START %s%s", cwd, direct_ini_contents);
system(fileName); /* run file */
return 0;
}So in redirect.ini you can put "program/program.exe", then place the exe in the main folder. When the user opens this exe, it'll actually open up the exe located inside the redirect.ini. Not sure if you need it as well, but if so, thank ColdDeath! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
As I understand it, you only need the "dist/program" directory. The build directory contains temporary files related to the building process, and the root directory of your program contains the source, which isn't needed once the program is packaged up with py2exe.
My TreeDemoWin.zip program I designed some time ago is packaged with py2exe, yet fits neatly in a single directory. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
I see... so where's the source file? I thought Python needs the source file to run because it's open-sourced. =S
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Python is open-source because the C source-code for the Python interpreter is open for anyone to read or adapt (if I recall, it has a BSD-like license). The reason that Python doesn't produce natively compiled programs is an another matter entirely; one that has technical, rather than legal, reasons.
Normally, Python takes a .py file and converts it into Python bytecode, which it then runs. In the case of imported modules, it caches this bytecode in .pyc files, so files don't need to be interpreted from scratch everytime they're run. As well as .py and .pyc files, there are .pyd files, which are actually just standard windows DLLs that have the Python C API, and .pyo files, which are standard Linux so libraries. There's probably something similar for Macs. I don't know how Py2exe works, but I do know that for each .py file in my program, py2exe created a matching .pyd file. I suspect what occurs is that py2exe generates the pyc bytecode for each .py file, and then does some binary magic which embeds this into a .pyd. Suffice to say, it works, and no source is required. |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() |
Oh, that's not bad at all then! I always assumed because Python was "Open-Source", that meant it could only be run with the source files left unchanged. Cool.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|