Jump to content

Python Portability


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...