Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45427

Re: executing python scripts that are symlinked

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
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; 'say,': 0.05; 'debugging': 0.07; 'importerror:': 0.07; 'string': 0.09; 'happens.': 0.09; 'imply': 0.09; 'subversion,': 0.09; 'sys,': 0.09; 'things,': 0.09; 'runs': 0.10; 'python': 0.11; 'windows': 0.15; '"file': 0.16; 'charles': 0.16; 'cmd': 0.16; 'codec': 0.16; 'cwd': 0.16; 'did,': 0.16; 'invocation': 0.16; 'os.getcwd()': 0.16; 'received:74.208.4.195': 0.16; 'script,': 0.16; 'somehow,': 0.16; 'symlink': 0.16; 'sys.path': 0.16; 'where?': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'module': 0.19; 'commit': 0.19; 'file,': 0.19; 'typing': 0.19; 'version.': 0.19; 'examples': 0.20; 'command': 0.22; '>>>': 0.22; 'import': 0.22; 'shell': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'comparing': 0.24; 'directory.': 0.24; 'example.': 0.24; 'package.': 0.24; 'platform,': 0.24; 'specify': 0.24; 'tells': 0.24; 'fine': 0.24; 'environment': 0.24; 'script': 0.25; 'second': 0.26; '2010,': 0.27; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'generally': 0.29; 'points': 0.29; "doesn't": 0.30; 'absolute': 0.30; 'is?': 0.30; "i'm": 0.30; 'gives': 0.31; 'that.': 0.31; 'usually': 0.31; 'directory,': 0.31; 'operations.': 0.31; 'subject:that': 0.31; 'though.': 0.31; 'file': 0.32; 'front': 0.32; 'regular': 0.32; 'run': 0.32; 'linux': 0.33; 'says': 0.33; 'running': 0.33; '(most': 0.33; 'guess': 0.33; 'copying': 0.34; 'there,': 0.34; 'could': 0.34; "can't": 0.35; 'display': 0.35; 'tool': 0.35; 'good.': 0.35; 'test': 0.35; 'but': 0.35; 'really': 0.36; "he's": 0.36; 'ubuntu': 0.36; 'shows': 0.36; 'should': 0.36; 'changing': 0.37; 'so,': 0.37; 'two': 0.37; 'skip:o 20': 0.38; 'system,': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'above,': 0.60; 'dave': 0.60; 'till': 0.61; "you're": 0.61; 'real': 0.63; 'different': 0.65; 'within': 0.65; 'production': 0.68; 'bothered': 0.68; 'line,': 0.68; 'received:74.208': 0.68; 'smith': 0.68; 'home': 0.69; 'different.': 0.84; 'seldom': 0.84; 'suspicion': 0.84; 'angel': 0.91
Date Thu, 16 May 2013 10:45:21 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5
MIME-Version 1.0
To python-list@python.org
Subject Re: executing python scripts that are symlinked
References <95bc1155-0a83-4ab1-8b76-68a819b2e29a@en2g2000vbb.googlegroups.com> <mailman.1741.1368692298.3114.python-list@python.org> <8640d5b0-5e6e-4a54-9584-6e7ffcdf1389@k3g2000vbn.googlegroups.com>
In-Reply-To <8640d5b0-5e6e-4a54-9584-6e7ffcdf1389@k3g2000vbn.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:k2zF0QpPFhFCpPUaFgXGUZqhaIbQs4o03TbaTiUVkZ8 Cucyz7XR+OPBZ3mORpSUUyjF9Ol2rzRIOIDwXv6bQBcwNEfNIw 7D67v/O0UpQpIFqki9VNjIUka7Vn7OwYT+FYQJUqR5EeQYn0SI o/deWUWmTAM2+y9v96eM00Ky4XsbULAvLC2ZlhQS8UlYNjJJM7 P4xBOE+X8PC9sndnxvB8ZOdssBcUjvS6QKCWgqI+o1FbT4dATh Et9KjZeqZvzoBG/qVuRNUcWGE1GaipFDINM8C+qn9mh66QgInk Kib1KD/FXSxLtKMijk03lsT18qGKmSi5pd8Kx4UqZ7jU8K2rQ= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1755.1368715536.3114.python-list@python.org> (permalink)
Lines 97
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368715536 news.xs4all.nl 15919 [2001:888:2000:d::a6]:50967
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45427

Show key headers only | View raw


On 05/16/2013 04:29 AM, Charles Smith wrote:
> On 16 Mai, 10:18, Dave Angel <da...@davea.name> wrote:
>> On 05/16/2013 03:48 AM, Charles Smith wrote:
>>
>>> Hi.
>>
>>> How can I say, from the cmd line, that python should take my CWD as my
>>> CWD, and not the directory where the script actually is?
>>
>>> I have a python script that works fine when it sits in directory WC,
>>> but if I move it out of WC to H and put a symlink from H/script to WC,
>>> it doesn't find the packages that are in WC.  Also, if I use the
>>> absolute path to H, it won't find them, but I guess I can understand
>>> that.
>>
>>> Someone said on the net that python doesn't know whether a file is
>>> real or a symlink, but I think that somehow, python is able to find
>>> out where the real file is and treat that as its base of operations.
>>
>> You'd really better specify your environment - exact OS and Python
>> version.  symlink and cwd usually imply a Unix-type system, but cmd is a
>> Windows thing.
>>
>> Then give examples of what your cwd is, what string you're typing at the
>> shell prompt, and what's happening.
>
>
> Well, I'm on a ubuntu platform,

Good.  Linux seldom gets in the way.

> running subversion, but I can't commit
> this debugging tool into the working copy where I'm using it, so I
> maintain it in my home directory.  The tool does use production
> packages, though.
>
> So, if I say,
>
>    $ python fapi-test.py
>
> and fapi-test.py really is there,

where?  Be explicit.  When copying the python invocation line above, you 
never bothered to include the current directory that's generally 
displayed right in front of that $ prompt.

> then it works, using the codec
> production package.

What codec production package.  And where is it installed?  And how do 
you intend that Python find it?

   But if I use a symlink instead,

So you delete the pfapi-tst.py out of the current directory, and create 
instead a symlink in the current directory that points to its real 
location  And without changing current directory, you run the same 
command and it runs till it gets to the import line, at which point it 
gives a traceback that has nothing to do with the file you're running??? 
  The traceback thinks you're running test2.py.

  it says
>
> Traceback (most recent call last):
>    File "test2", line 1, in <module>
>      from codec.support import *
> ImportError: No module named codec.support
>
>
> Python tells me Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
>
>

Take a look at Stephen's example.  He runs some things, shows you 
exactly what he's running, and what happens.  The things he runs may not 
match what you did, but we cannot tell.

 From within your script, you can display os.getcwd(), you can ...


import sys, os
print "cwd is", os.getcwd()
print "file is",  __file__
print "PATH is", os.getenv("PATH")
print "python-path is", os.getenv("PYTHONPATH")
print "sys.path is", sys.path

import codec
print "codec file is", codec.__file__

if you run that both as a regular file and on a symlink pointing to that 
file, comparing the two runs could give you a clue as to what's 
different.  My suspicion is that you have a different cwd when you test 
it the second way.

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

executing python scripts that are symlinked Charles Smith <cts.private.yahoo@gmail.com> - 2013-05-16 00:48 -0700
  Re: executing python scripts that are symlinked Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-16 03:12 -0500
  Re: executing python scripts that are symlinked Dave Angel <davea@davea.name> - 2013-05-16 04:18 -0400
    Re: executing python scripts that are symlinked Charles Smith <cts.private.yahoo@gmail.com> - 2013-05-16 01:29 -0700
      Re: executing python scripts that are symlinked Dave Angel <davea@davea.name> - 2013-05-16 10:45 -0400
  Re: executing python scripts that are symlinked Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-16 09:04 +0000
    Re: executing python scripts that are symlinked Charles Smith <cts.private.yahoo@gmail.com> - 2013-05-16 02:23 -0700

csiph-web