Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Finding the right Python executable on Windows

Reply
Thread Tools

Finding the right Python executable on Windows

 
 
Geoff Bache
Guest
Posts: n/a
 
      01-25-2011
Hi all,

I have a Python process on Windows and would like to start a Python
subprocess using the same interpreter. I wonder how to go about this?

First, I tried the obvious

subprocess.Popen([ sys.executable, "subproc.py", ... ])

but that fails, because my process has a "native launcher", (i.e. C:
\path\mylauncher.exe, which is just a wrapper around the Python
program) and hence sys.executable returns this path instead of the
interpreter location. It isn't appropriate to use the launcher for the
subprocess.

I also tried using sys.exec_prefix but there didn't seem to be any
standard location for the interpreter under this directory in any
case.

I feel certain there must be some way to do this as it seems a rather
basic thing somehow, can anyone give me a hint?

Regards,
Geoff Bache
 
Reply With Quote
 
 
 
 
Geoff Bache
Guest
Posts: n/a
 
      01-26-2011
On Tue, Jan 25, 2011 at 3:24 PM, Brian Curtin <(E-Mail Removed)> wrote:
> On Tue, Jan 25, 2011 at 04:25, Geoff Bache <(E-Mail Removed)> wrote:
>>
>> Hi all,
>>
>> I have a Python process on Windows and would like to start a Python
>> subprocess using the same interpreter. I wonder how to go about this?
>>
>> First, I tried the obvious
>>
>> subprocess.Popen([ sys.executable, "subproc.py", ... ])
>>
>> but that fails, because my process has a "native launcher", (i.e. C:
>> \path\mylauncher.exe, which is just a wrapper around the Python
>> program) and hence sys.executable returns this path instead of the
>> interpreter location. It isn't appropriate to use the launcher for the
>> subprocess.
>>
>> I also tried using sys.exec_prefix but there didn't seem to be any
>> standard location for the interpreter under this directory in any
>> case.
>>
>> I feel certain there must be some way to do this as it seems a rather
>> basic thing somehow, can anyone give me a hint?
>>
>> Regards,
>> Geoff Bache

>
> If*sys.executable doesn't work due to this "native launcher", you could
> try*something like this:
>>>> import os
>>>> import sys
>>>> full_path = None
>>>> for path in sys.path:

> ... * * full = os.path.join(path, "python.exe")
> ... * * if os.path.exists(full):
> ... * * * * * * full_path = full
> ...
>>>> full_path

> 'c:\\python31\\python.exe'


Thanks Brian!

It never occurred to me that the Python executable would be on
sys.path, but it seems to be on the installations I've tried on
Windows. It isn't on other platforms of course, but it's easy enough
to only do this on Windows.

I wonder why it's like this? I can't see anything in that directory I
could import...

Regards,
Geoff
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding location of an executable in a windows machine? nonsense@mynonsense.net Python 3 05-15-2009 07:59 PM
Create executable from executable with py2exe vedrandekovic@gmail.com Python 0 03-29-2008 12:23 PM
Running an Executable Before Executable JAR Jason Cavett Java 8 05-16-2007 07:14 PM
what is fast dynamically linked executable or statically linked executable ?how to decide? pratap C Programming 20 03-07-2007 04:46 AM
How can I run a c executable in pwd ,while the executable is in some other directory vishsid3@gmail.com C Programming 15 08-21-2006 06:04 AM



Advertisments