SPSS / Python - compiler

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

SPSS / Python - compiler

drfg2008
is it possible to compile SPSS - Python source code and generate Python bytecode (machinecode) that runs on SPSS ?

Thanks
Dr. Frank Gaeth

Reply | Threaded
Open this post in threaded view
|

Re: SPSS / Python - compiler

Albert-Jan Roskam

 
If you use an import statement to import Python code, a byte-compiled (.pyc) version of your program (.py) is automatically created, if it does not already exist, unless you made changes to your program, in which case the .pyc is created again.
 
Be sure that Python knows where to find your program. You can add your program location to the PYTHONPAD environment variable, or use
import sys
sys.path.append("d:/mypath")
import myprogram  # ---> here's when the bytecompiled myprogram.pyc gets created.
# now you can access stuff inside the program, e.g. functions
myprogram.funcname(arg)
 
 
Cheers!!
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



From: drfg2008 <[hidden email]>
To: [hidden email]
Sent: Mon, June 20, 2011 11:48:29 AM
Subject: [SPSSX-L] SPSS / Python - compiler

is it possible to compile SPSS - Python source code and generate Python
bytecode (machinecode) that runs on SPSS ?

Thanks

-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-Python-compiler-tp4505740p4505740.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: SPSS / Python - compiler

Jon K Peck
As Albert-Jan said, Python source code is automatically compiled and written to a .pyc file, except in a few special cases.   However, you can force code to be compiled for situations where you might want only to distribute the compiled form or if you have a very large set of code and don't want the user to wait (briefly) for compilation to occur.  Besides importing the code to trigger compilation, there are modules that can force compilation such as compileall.

However, the Python byte code is not as optimized as, say, Java byte code, so if you are looking for native code for speed improvements, compiling to byte code won't help much.  There are tools such as psycho that will compile Python code to native machine code with some restrictions.

HTH,



Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Albert-Jan Roskam <[hidden email]>
To:        [hidden email]
Date:        06/20/2011 04:59 AM
Subject:        Re: [SPSSX-L] SPSS / Python - compiler
Sent by:        "SPSSX(r) Discussion" <[hidden email]>






If you use an import statement to import Python code, a byte-compiled (.pyc) version of your program (.py) is automatically created, if it does not already exist, unless you made changes to your program, in which case the .pyc is created again.
 
Be sure that Python knows where to find your program. You can add your program location to the PYTHONPAD environment variable, or use
import sys
sys.path.append("d:/mypath")
import myprogram  # ---> here's when the bytecompiled myprogram.pyc gets created.
# now you can access stuff inside the program, e.g. functions
myprogram.funcname(arg)
 
 
Cheers!!
Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




From: drfg2008 <[hidden email]>
To:
[hidden email]
Sent:
Mon, June 20, 2011 11:48:29 AM
Subject:
[SPSSX-L] SPSS / Python - compiler


is it possible to compile SPSS - Python source code and generate Python
bytecode (machinecode) that runs on SPSS ?

Thanks

-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Python-compiler-tp4505740p4505740.html
Sent from the SPSSX Discussion mailing list archive at
Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to

LISTSERV@... (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: SPSS / Python - compiler

drfg2008
Thanks Albert-Jan, thanks Jon!


(yes, this is the reason: for situations where I only want to distribute the compiled form - not so much speed)

Frank
Dr. Frank Gaeth

Reply | Threaded
Open this post in threaded view
|

Re: SPSS / Python - compiler

Jon K Peck
If you are only distributing the .pyc (or .pyo) form, there are two things you should be aware of
1. This does not really prevent someone from reverse engineering your code.  It can be decompiled into something equivalent to the original using standard Python tools.

2. If you have users on different versions of SPSS that use different versions of Python, you will need to distribute a .pyc for each version.  The byte codes are version specific and might not work with all the versions you need to support.

Regards,

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        drfg2008 <[hidden email]>
To:        [hidden email]
Date:        06/21/2011 05:03 AM
Subject:        Re: [SPSSX-L] SPSS / Python - compiler
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Thanks Albert-Jan, thanks Jon!


(yes, this is the reason: for situations where I only want to distribute the
compiled form - not so much speed)

Frank

-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Python-compiler-tp4505740p4510175.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: SPSS / Python - compiler

Albert-Jan Roskam
Perhaps py2exe could be used to distribute the program as .exe? A bit cumbersome though (e.g., emailing .exe files). I'd just distribute the .py.
 
Cheers!!
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



From: Jon K Peck <[hidden email]>
To: [hidden email]
Sent: Tue, June 21, 2011 2:59:05 PM
Subject: Re: [SPSSX-L] SPSS / Python - compiler

If you are only distributing the .pyc (or .pyo) form, there are two things you should be aware of
1. This does not really prevent someone from reverse engineering your code.  It can be decompiled into something equivalent to the original using standard Python tools.

2. If you have users on different versions of SPSS that use different versions of Python, you will need to distribute a .pyc for each version.  The byte codes are version specific and might not work with all the versions you need to support.

Regards,

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        drfg2008 <[hidden email]>
To:        [hidden email]
Date:        06/21/2011 05:03 AM
Subject:        Re: [SPSSX-L] SPSS / Python - compiler
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Thanks Albert-Jan, thanks Jon!


(yes, this is the reason: for situations where I only want to distribute the
compiled form - not so much speed)

Frank

-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Python-compiler-tp4505740p4510175.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

Reply | Threaded
Open this post in threaded view
|

Re: SPSS / Python - compiler

Jon K Peck
Setting up py2exe can be challenging, but even if you do that, assuming that this Python code to run within SPSS, you wouldn't have the connection for this.  You would just have an exe.  If you were doing this in external mode, I'm afraid that you would be trying to build an untenable exe file including all of Statistics.  I've never tried very hard to get Statistics into a py2exe package as that seems to be akin to the snake swallowing the crocodile.

Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Albert-Jan Roskam <[hidden email]>
To:        [hidden email]
Date:        06/21/2011 07:51 AM
Subject:        Re: [SPSSX-L] SPSS / Python - compiler
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Perhaps py2exe could be used to distribute the program as .exe? A bit cumbersome though (e.g., emailing .exe files). I'd just distribute the .py.

Cheers!!
Albert-Jan



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




From: Jon K Peck <[hidden email]>
To:
[hidden email]
Sent:
Tue, June 21, 2011 2:59:05 PM
Subject:
Re: [SPSSX-L] SPSS / Python - compiler


If you are only distributing the .pyc (or .pyo) form, there are two things you should be aware of

1. This does not really prevent someone from reverse engineering your code.  It can be decompiled into something equivalent to the original using standard Python tools.


2. If you have users on different versions of SPSS that use different versions of Python, you will need to distribute a .pyc for each version.  The byte codes are version specific and might not work with all the versions you need to support.


Regards,


Jon Peck
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621





From:        
drfg2008 <[hidden email]>
To:        
[hidden email]
Date:        
06/21/2011 05:03 AM
Subject:        
Re: [SPSSX-L] SPSS / Python - compiler
Sent by:        
"SPSSX(r) Discussion" <[hidden email]>




Thanks Albert-Jan, thanks Jon!


(yes, this is the reason: for situations where I only want to distribute the
compiled form - not so much speed)

Frank

-----
Dr. Frank Gaeth
FU-Berlin

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Python-compiler-tp4505740p4510175.html
Sent from the SPSSX Discussion mailing list archive at
Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD