Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Windows': 0.02; 'scripts': 0.03; 'subject:Python': 0.06; 'interpreter.': 0.07; 'modify': 0.07; 'subject:installation': 0.07; 'function,': 0.09; 'preferable': 0.09; 'subject:script': 0.09; 'sys.platform': 0.09; 'cc:addr:python-list': 0.11; 'martin': 0.11; 'python': 0.11; "wouldn't": 0.14; '"win32":': 0.16; 'args[0]': 0.16; 'argument.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'is;': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'personally,': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'simpson': 0.16; 'situation.': 0.16; 'unpacked': 0.16; 'wrote:': 0.18; 'library': 0.18; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'subject:problem': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'extension': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'unix': 0.29; 'wonder': 0.29; 'involving': 0.30; 'especially': 0.30; "i'm": 0.30; 'code': 0.31; 'correctly.': 0.31; 'datum': 0.31; 'invoke': 0.31; 'location,': 0.31; 'really,': 0.31; 'testing.': 0.31; 'file': 0.32; 'stuff': 0.32; 'maybe': 0.34; 'subject:from': 0.34; 'could': 0.34; 'subject: (': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'machine.': 0.36; 'searching': 0.37; 'stable': 0.38; 'files': 0.38; 'how': 0.40; 'easy': 0.60; 'catch': 0.60; 'disclaimer:': 0.60; 'hope': 0.61; 'full': 0.61; 'john': 0.61; 'content-disposition:inline': 0.62; 'kind': 0.63; 'face': 0.64; 'temporary': 0.65; 'to:addr:gmail.com': 0.65; 'received:192.168.15': 0.84 Date: Thu, 27 Mar 2014 08:27:32 +1100 From: Cameron Simpson To: Martin Landa Subject: Re: calling Python script from another Python script (Windows, multiple installation problem) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <6ba81449-5f4c-46be-ad4a-64ea8bc5b436@googlegroups.com> Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395869262 news.xs4all.nl 2928 [2001:888:2000:d::a6]:36883 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69146 On 26Mar2014 05:49, Martin Landa wrote: > Dne středa, 26. března 2014 13:29:47 UTC+1 Martin Landa napsal(a): > > not really, I am just searching for a better solution based on virtualenv or something similar... > > particularly I am using something like > > if sys.platform == "win32": > # get full path including file extension for scripts > fcmd = get_real_command(args[0]) > if fcmd.endswith('.py'): > args[0] = fcmd > args.insert(0, sys.executable) > > where 'args' in subprocess.Popen's argument. I just wonder if > there is a better or preferable solution over this kind of a hack. Personally, the above is what I would do in your situation. Any solution involving virtualenv or the like will still need to point at the right python executable. Provided your code above is in a handy function, I wouldn't modify it. What virtualenv (presumably a virtualenv bundled in your package) _will_ give you is a stable and predictable collection of library files to go with your python interpreter. That could well be a significant benefit, especially in the face or an unknown target machine. So you may have a good case for putting a virtualenv in your bundle, but still using the _same_ code above to invoke stuff - the python in the virtualenv will set its sys.path, so the easy way is to use your existing code to access the virtualenv python executable. The only catch is that I do not know how mobile a virtualenv is; if your bundle is unpacked in an unknown temporary location, maybe virtualenv won't work correctly. Needs testing. Disclaimer: I'm a UNIX guy. Just my 2c. Hope it is helpful, -- Cameron Simpson Carpe Datum - John Sloan