472,364 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

Using Python To Launch Python

aha
Hello All,
I have a situation where I can count on a Python installation being
available on a system, but I can't count on it being a version of
Python needed by my application. Since my application has it's own
version of Python installed with it how should I use the system Python
to launch the version of Python that launches my Application. Yes,
this is a convoluted process, but not all Pythons are built the
same :)

Right now I am leaning towards using exec to start a new process, but
I thought I would check to see if anyone else has had the need to
perform a task similar to this one.

AHA
Jul 14 '08 #1
5 1338
On Mon, Jul 14, 2008 at 02:01:04PM -0700, aha wrote:
Since my application has it's own version of Python installed with
it how should I use the system Python to launch the version of
Python that launches my Application. Yes, this is a convoluted
process, but not all Pythons are built the same :)
/usr/local/bin/$APPNAME:

#!/bin/sh

INSTALLPATH=<wherever app is installed>
PATH=$INSTALLPATH/bin:$PATH
exec $INSTALLPATH/bin/python $APPNAME "$@"

Doesn't get much simpler than that. :) You can certainly do the
equivalent in Python... there's not much difference. Slightly less
typing in bourne/bash shell, I guess...

--
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFIe8QmdjdlQoHP510RAsFMAJ0bs2ikCfdLfkgIk/nczw4KH63ZjwCfWiAi
LuLK54OvQcANMNItfeR0aks=
=gq7l
-----END PGP SIGNATURE-----

Jul 14 '08 #2
On Jul 14, 4:01*pm, aha <aquil.abdul...@gmail.comwrote:
Hello All,
* I have a situation where I can count on a Python installation being
available on a system, but I can't count on it being a version of
Python needed by my application. *Since my application has it's own
version of Python installed with it how should I use the system Python
to launch the version of Python that launches my Application. *Yes,
this is a convoluted process, but not all Pythons are built the
same :)

Right now I am leaning towards using exec to start a new process, but
I thought I would check to see if anyone else has had the need to
perform a task similar to this one.

AHA
As an alternative, you may be able to use the subprocess module of
Python to do this too.

Mike
Jul 14 '08 #3
aha wrote:
Hello All,
I have a situation where I can count on a Python installation being
available on a system, but I can't count on it being a version of
Python needed by my application. Since my application has it's own
version of Python installed with it how should I use the system Python
to launch the version of Python that launches my Application. Yes,
this is a convoluted process, but not all Pythons are built the
same :)

Right now I am leaning towards using exec to start a new process, but
I thought I would check to see if anyone else has had the need to
perform a task similar to this one.

AHA
You didn't tell us what operating system, but if by chance it is Windows you
should use py2exe to package up your program (along with the proper
pythonXX.dll) into a distributable package.

On Linux, others have posted answers.

-Larry
Jul 14 '08 #4
On Mon, Jul 14, 2008 at 05:40:43PM -0400, Aquil H. Abdullah wrote:
You've hit the proverbial nail with the hammer. The problem is that my
application needs to run under both the Linux and Windows OSs, so while I
would love to use a nice sh, csh, or bash shell script. My hands are tied
because Windows does not provide such wonderful shells.
*Provides*, no... neither does it provide Python, for what that's
worth. But you can certainly get it (bash):

http://win-bash.sourceforge.net/

I suppose it's not worth installing just for this purpose though...
But you can provide with your application a DoS batch file that does
exactly the same thing (in addition to a shell script). The user
would quite intuitively use whichever were appropriate, or follow your
provided directions otherwise. Or, the equivalent in (hopefully
OS-agnostic) Python:

import os, sys

# I believe this gets the name of the root in all major OSes
def root_dir(path):
if os.path.dirname(path) == path:
return path
return (root_dir(os.path.dirname(path)))

appname = <name of your python script>
root = root_dir(os.getcwd())
install_path = os.path.join(root, "usr")
bin_path = os.path.join(install_path, "bin")
os.environ["PATH"] = bin_path + os.pathsep + os.environ["PATH"]
python_path = os.path.join(bin_path, "python")
args = sys.argv[1:]
args.insert(0, os.path.join(bin_path, appname))
args.insert(0, python_path)
args.insert(0, python_path)
os.execv(python_path, args)


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFIe/G4HEnASN++rQIRAsZcAKC8HRYRD8ysjmVGNzYVozzeL/27gACdEvLw
7d9Nwv9bzbvSTYEgOSgx3m0=
=4xtx
-----END PGP SIGNATURE-----

Jul 15 '08 #5
En Mon, 14 Jul 2008 21:39:20 -0300, Derek Martin <co**@pizzashack.org>
escribió:
On Mon, Jul 14, 2008 at 05:40:43PM -0400, Aquil H. Abdullah wrote:
>You've hit the proverbial nail with the hammer. The problem is that my
application needs to run under both the Linux and Windows OSs, so while
I
would love to use a nice sh, csh, or bash shell script. My hands are
tied
because Windows does not provide such wonderful shells.

*Provides*, no... neither does it provide Python, for what that's
worth. But you can certainly get it (bash):

http://win-bash.sourceforge.net/
Using the standard cmd.exe, the previously posted shell script becomes:

=== begin appname.cmd ===
set INSTALLPATH=<wherever app is installed>
call %INSTALLPATH%\bin\python %INSTALLPATH%\APPNAME.py %*
=== end appname.cmd ===

--
Gabriel Genellina

Jul 15 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

467
by: mike420 | last post by:
THE GOOD: 1. pickle 2. simplicity and uniformity 3. big library (bigger would be even better) THE BAD:
9
by: Jeff Wagner | last post by:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to getting started? Thanks, Jeff
6
by: aurora | last post by:
Sometimes it is rather frustrated to use the Python Library Reference. It seems each section is hand crafted and it is up to the author decide the organization and coverage. For example the os...
13
by: Marcel van den Dungen | last post by:
Does anybody know how to use Python as the scripting language for HTML applications? I tried the following, but I get a script error ('Object expected') on the body element. <html> <head>...
0
by: Milon | last post by:
I have 2 computers hooked to the same network. One of the computer has Python installed, and I want to write a python script to launch "c:\notepad.exe" on the second computer, how do I do this? ...
0
by: Fuzzyman | last post by:
It's finally happened, `Movable Python <http://www.voidspace.org.uk/python/movpy/>`_ is finally released. Versions for Python 2.3 & 2.4 are available from `The Movable Python Shop...
8
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I would like to find out how I can launch an independent Python program from existing one in a cross-platform way. The result I am after is that a new terminal window should open (for io...
0
by: Ivan Ven Osdel | last post by:
>Hello All, Simplest case: Obviously things can be shortened by adding to the PATH. Ivan Ven Osdel Software Engineer
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.