RhYtHmMaStEr Posted June 14, 2015 Share Posted June 14, 2015 I am relatively new to Python and wanted to get some feedback on its overall portability from OS to OS. MAC and Linux seem to have the interpreter built in. When making OS calls do they generally port well in the respective interpreter per OS or is there some minor tweaking that must occur? Quote Link to comment Share on other sites More sharing options...
cooper Posted June 14, 2015 Share Posted June 14, 2015 I was under the impression that if the interpreter is there and none of the modules you depend upon in your program are "extender modules" things should just work and behave the same as on any other OS. Quote Link to comment Share on other sites More sharing options...
RhYtHmMaStEr Posted June 15, 2015 Author Share Posted June 15, 2015 Thanks Cooper! So if I wanted to make a ./executable file in Linux or MAC its just a matter of chmod +x the .py file? Quote Link to comment Share on other sites More sharing options...
Oli Posted June 15, 2015 Share Posted June 15, 2015 Best to stick a shebang at the top of the file for convenience too. Quote Link to comment Share on other sites More sharing options...
RhYtHmMaStEr Posted June 16, 2015 Author Share Posted June 16, 2015 Thank Oli. I am unfamiliar with the SheBang. I have heard the term is that the process of including the interpreter in the build? How does it work exactly say to create a stand alone executable such as ./runme from runme.py? Thanks. Quote Link to comment Share on other sites More sharing options...
cooper Posted June 16, 2015 Share Posted June 16, 2015 The "SheBang" is the "#!" at the start of a script, which should be followed by the full path to the program that can interpret said script. So for a shell script the common thing to do is to start the script with "#!/bin/sh" but if your script actually requires bash it would start with "#!/bin/bash" In case of a Python script, the typical location of the interpreter is /usr/bin/python so you start your script with "#!/usr/bin/python" Quote Link to comment Share on other sites More sharing options...
Oli Posted June 16, 2015 Share Posted June 16, 2015 Exactly - so on linux the file extension is unimportant - with the shebang in the file, the file can simply be called 'runme'. Then you can run it with ./runme after it is made executable. './runme' is a bit nicer than 'python runme.py' On windows you would have to have the '.py' extension and then you mess around with the registry (if my memory serves me correct) to allow it to be executed directly as 'runme.py'. Quote Link to comment Share on other sites More sharing options...
newbi3 Posted June 17, 2015 Share Posted June 17, 2015 How does it work exactly say to create a stand alone executable such as ./runme from runme.py? Thanks. Python isn't a compiled program so it can't be stand alone. There are projects like py2exe and pyinstaller that create stand alone executables from your python script by including all of the libs in the binary. It works pretty well. Quote Link to comment Share on other sites More sharing options...
fugu Posted June 18, 2015 Share Posted June 18, 2015 There are projects like py2exe and pyinstaller that create stand alone executables from your python script by including all of the libs in the binary. It works pretty well. lol I downloaded py2exe just 1 week ago for the first time. Haven't had any time to play with it but looked neat. Quote Link to comment Share on other sites More sharing options...
Sud0x3 Posted June 20, 2015 Share Posted June 20, 2015 This may be of interest, https://github.com/pantsbuild/pex Quote Link to comment Share on other sites More sharing options...
Black-Assassin Posted July 2, 2015 Share Posted July 2, 2015 if you want just compile python file you may need py2exe or pyinstaller those are the ones i have used. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.