Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 6th, 2005, 4:54 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,884
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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;
}
It reads the contents of "redirect.ini", appends it to the current working directory, and opens that file.

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!
Sane is offline   Reply With Quote
Old Dec 7th, 2005, 6:37 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Dec 7th, 2005, 3:01 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,884
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
I see... so where's the source file? I thought Python needs the source file to run because it's open-sourced. =S
Sane is offline   Reply With Quote
Old Dec 7th, 2005, 3:25 PM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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.
Arevos is offline   Reply With Quote
Old Dec 7th, 2005, 4:27 PM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,884
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:23 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC