Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!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; 'bug': 0.02; 'ide': 0.05; 'run-time': 0.05; 'sys': 0.05; 'importerror:': 0.07; 'paths': 0.07; 'subject:changing': 0.07; 'wrapper': 0.07; 'eclipse': 0.09; 'skip:" 60': 0.09; 'am,': 0.12; 'heavily': 0.15; 'skip:" 40': 0.15; 'cc:addr:python-list': 0.15; '"import': 0.16; 'happy,': 0.16; 'importerror': 0.16; 'paths?': 0.16; 'runner': 0.16; 'somehow.': 0.16; 'spam"': 0.16; 'then?': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'traceback.': 0.16; 'wingide': 0.16; 'wrote:': 0.16; 'wed,': 0.17; "haven't": 0.20; 'checked': 0.20; '(most': 0.21; 'cc:no real name:2**0': 0.21; '(but': 0.21; 'file,': 0.21; "doesn't": 0.22; 'feb': 0.22; 'header :In-Reply-To:1': 0.22; 'runs': 0.23; 'works.': 0.23; 'traceback': 0.24; 'cc:2**0': 0.25; 'loaded': 0.25; 'guess': 0.25; 'module': 0.26; 'work,': 0.26; 'import': 0.27; 'fact': 0.27; 'looks': 0.27; 'posted': 0.27; "i'm": 0.27; 'idle': 0.28; "skip:' 10": 0.29; 'problem': 0.29; 'cc:addr:python.org': 0.29; 'solved': 0.30; 'skip:l 30': 0.32; 'received:209.85.214': 0.32; "can't": 0.32; 'message-id:@gmail.com': 0.33; 'header:User-Agent:1': 0.33; 'named': 0.33; 'there': 0.33; 'calling': 0.34; 'last):': 0.34; 'skip:" 50': 0.34; 'changing': 0.34; 'something': 0.35; 'things': 0.35; 'junk': 0.35; 'file': 0.35; 'run': 0.37; 'entry': 0.37; 'list,': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'using': 0.37; 'could': 0.37; 'steven': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'point': 0.39; 'absolute': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'might': 0.40; 'matter': 0.61; 'covers': 0.64; 'forced': 0.67; 'same,': 0.67; 'andrea': 0.84; "shouldn't,": 0.84; 'points,': 0.91; 'story.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=XkG1YAVe3ZGBJcGzfgxxUwy6SXvgo4ipVZGjXlyLCMY=; b=G7i2zbwAf2JXJQ6EUTrk2tYNrxOx2nc0fQj8Ffi1HQCXwR7cxl8xfwKnaaSetF+LHv 8U90MqqPKQGGPwWpzFCIaW4+jdMlYQaxeDk+PBnq+oWRpm4MFzfIDybuXG2hkeYkFYHd OCsI1q5uLzIUsvM61auUUKGZbiNnnDzYEk+Cg= Date: Thu, 02 Feb 2012 10:03:42 +0000 From: Andrea Crotti User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111224 Thunderbird/9.0.1 MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: changing sys.path References: <4F296509.60607@gmail.com> <4f29de16$0$29989$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4f29de16$0$29989$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328177026 news.xs4all.nl 6953 [2001:888:2000:d::a6]:51579 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19783 On 02/02/2012 12:51 AM, Steven D'Aprano wrote: > On Wed, 01 Feb 2012 17:47:22 +0000, Andrea Crotti wrote: > >> Yes they are exactly the same, because in that file I just write exactly >> the same list, >> but when modifying it at run-time it doesn't work, while if at the >> application start >> there is this file everything works correctly... >> >> That's what really puzzles me.. What could that be then? > > Are you using IDLE or WingIDE or some other IDE which may not be > honouring sys.path? If so, that's a BAD bug in the IDE. > Are you changing the working directory manually, by calling os.chdir? If > so, that could be interfering with the import somehow. It shouldn't, but > you never know... > > Are you adding absolute paths or relative paths? No, no and absolute paths.. > > You say that you get an ImportError, but that covers a lot of things > going wrong. Here's a story. Could it be correct? I can't tell because > you haven't posted the traceback. > > When you set site-packages/my_paths.pth you get a sys path that looks > like ['a', 'b', 'fe', 'fi', 'fo', 'fum']. You then call "import spam" > which locates b/spam.py and everything works. > > But when you call sys.path.extend(['a', 'b']) you get a path that looks > like ['fe', 'fi', 'fo', 'fum', 'a', 'b']. Calling "import spam" locates > some left over junk file, fi/spam.py or fi/spam.pyc, which doesn't > import, and you get an ImportError. > > And no the problem is not that I already checked inspecting at run-time.. This is the traceback and it might be related to the fact that it runs from the .exe wrapper generated by setuptools: Traceback (most recent call last): File "c:\python25\scripts\dev_main-script.py", line 8, in load_entry_point('psi.devsonly==0.1', 'console_scripts', 'dev_main')() File "h:\git_projs\psi\psi.devsonly\psi\devsonly\bin\dev_main.py", line 152, in main Develer(ns).full_run() File "h:\git_projs\psi\psi.devsonly\psi\devsonly\bin\dev_main.py", line 86, in full_run run(project_name, test_only=self.ns.test_only) File "h:\git_projs\psi\psi.devsonly\psi\devsonly\environment.py", line 277, in run from psi.devsonly.run import Runner File "h:\git_projs\psi\psi.devsonly\psi\devsonly\run.py", line 7, in from psi.workbench.api import Workbench, set_new_dev_main ImportError: No module named workbench.api Another thing which might matter is that I'm launching Envisage applications, which heavily rely on the use of entry points, so I guess that if something is not in the path the entry point is not loaded automatically (but it can be forced I guess somehow). I solved in another way now, since I also need to keep a dev_main.pth in site-packages to make Eclipse happy, just respawning the same process on ImportError works already perfectly..