LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Convert python script to windows executable (https://www.linuxquestions.org/questions/linux-newbie-8/convert-python-script-to-windows-executable-673664/)

ankit_mcgill 10-01-2008 11:36 PM

Convert python script to windows executable
 
Hi all,

I made a python script using Qt for a nice gui that reads the dvd in the drive, catalogues all the movies/files on the disk and stores them in a db so that when i want to watch a movie from my collection i can simply put in the name and it will tell me what disk the movie is in.

now the problem is i want to port this python script to a windows executable so that i can run this on my windows desktop as well.

had some questions/concerns regarding this .. hoping someone can help :

1. since the script uses qt first of all can it be ported to windows ?

2. in the script itself i use some native linux commands like 'du' .. would i need to change them to something else if i port ?

3. what about all the packages like pydb that i have importted in the script ? so they get compiled in the final .exe automatically ?

this little script has been a much needed time saver for me and i would really love to be able to run it on windows ... even thought about coding it in C on windows .. but why waste time if i can manage to port the same python code to an .exe.

thanks for the help
-ankit

i92guboj 10-01-2008 11:51 PM

Quote:

Originally Posted by ankit_mcgill (Post 3297632)
1. since the script uses qt first of all can it be ported to windows ?

It depends. It should be easily portable, as long as the python bindings and all the other extensions you use (if any) are also working in windows.

About qt: I think that qt3 has no free license for windows. If you used qt4 you are not going to have problems. You should be able to compile it in windows with very little work. But it all depends on the application. Some apps use OS specific code, others do not...

Quote:

2. in the script itself i use some native linux commands like 'du' .. would i need to change them to something else if i port ?
Sure.

That's why it's a good thing to stick to standard ANSI libs (or qt, or whatever libs you are using). If you use libraries that are available in many architectures and OSes, and stick to the standard libraries of your chosen language, then you are going to have a much easier life. If you use external tools and libraries that are OS dependant, then you are going to have to reprogram that part of the program each time to want to use a new OS.

Quote:

3. what about all the packages like pydb that i have importted in the script ? so they get compiled in the final .exe automatically ?
I know very little about python and I know nothing about python object code compilers. I guess that depends entirely on the compiler you use, and whether you link all the stuff statically or whatever... I am a complete profane when it comes to compiling languages languages that are meant to be interpreted.

Quote:

this little script has been a much needed time saver for me and i would really love to be able to run it on windows ... even thought about coding it in C on windows .. but why waste time if i can manage to port the same python code to an .exe.

thanks for the help
-ankit
Now, a silly question: python does run in windows as well as a whole of of other OSes. Why compile an exe? Why not just run it as you run it in linux? Just install python and let it do its job.

If you are wanting to do so to override the dependencies, forget about it. You will still need everything you need on linux to run it. So, if you are using functionalities that are linux-only you are going to have to re-make some bits.

ankit_mcgill 10-02-2008 12:54 AM

Quote:

Now, a silly question: python does run in windows as well as a whole of of other OSes. Why compile an exe? Why not just run it as you run it in linux? Just install python and let it do its job.

If you are wanting to do so to override the dependencies, forget about it. You will still need everything you need on linux to run it. So, if you are using functionalities that are linux-only you are going to have to re-make some bits.
i am just trying to avoid having to install python on my desktop as i know i wouldnt use it for anything else/

hmm ... is that the whole point of compiling it into a nice little exe file so that i do not need python on the windows computer to interpret my script ? also if i did manage to compile it into an exe why would i need the dependencies ? shouldnt they be compiled in as well ??

thanks
-ankit

i92guboj 10-03-2008 11:11 AM

There might be tools that can embed the python modules on a single exe file so your program can import them from there. I am not sure if there's anything to embed the rest of libraries like qt, however, even if there is, you need to make sure that everything needed is available for windows.

Supposing that statically linking libs into a python compiled object code, you can't expect to embed a linux qt .so file into such a file and hope that it will work in windows. You need the windows libs. And you definitely need to make sure that all the tools you use (for example, "du" as you said) are also available. There's no way to magically port your code if it's not designed to be portable.

ankit_mcgill 10-05-2008 01:21 AM

Quote:

Originally Posted by i92guboj (Post 3299109)
There might be tools that can embed the python modules on a single exe file so your program can import them from there. I am not sure if there's anything to embed the rest of libraries like qt, however, even if there is, you need to make sure that everything needed is available for windows.

Supposing that statically linking libs into a python compiled object code, you can't expect to embed a linux qt .so file into such a file and hope that it will work in windows. You need the windows libs. And you definitely need to make sure that all the tools you use (for example, "du" as you said) are also available. There's no way to magically port your code if it's not designed to be portable.

well put ! ... another lesson learned . always keep the future in mind !


All times are GMT -5. The time now is 07:18 PM.