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


Groups > comp.lang.python > #19465 > unrolled thread

import fails in non-interactive interpreter

Started byBrian <brian.brinegar@gmail.com>
First post2012-01-25 18:25 -0800
Last post2012-01-26 09:37 -0500
Articles 6 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  import fails in non-interactive interpreter Brian <brian.brinegar@gmail.com> - 2012-01-25 18:25 -0800
    Re: import fails in non-interactive interpreter Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-01-25 22:04 -0500
    Re: import fails in non-interactive interpreter Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-26 11:58 +0100
    Re: import fails in non-interactive interpreter Brian Brinegar <brian.brinegar@gmail.com> - 2012-01-26 07:47 -0500
    Re: import fails in non-interactive interpreter Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-26 14:49 +0100
    Re: import fails in non-interactive interpreter Brian Brinegar <brian.brinegar@gmail.com> - 2012-01-26 09:37 -0500

#19465 — import fails in non-interactive interpreter

FromBrian <brian.brinegar@gmail.com>
Date2012-01-25 18:25 -0800
Subjectimport fails in non-interactive interpreter
Message-ID<9115def9-c2f6-4ac9-ae4b-8b1b8867ba7b@c21g2000yqi.googlegroups.com>
I've been banging my head against this for the past hour, and I'm
hoping someone here can set me straight.

I have a virtualenv setup for a Pyramid app and I'm having trouble
importing the paste.deploy module in a standalone, non-Pyramid script
within the virtualenv.

For testing purposes I have a one line "test.py" file:

from paste.deploy import appconfig

> python test.py
ImportError: No module named paste.deploy

but, using the same same python, I'm able to import the module from
the interactive interpreter. The PATH and PYTHONPATH environment
variables are identical in both contexts.

Under what situations would a module be available to through the
interactive interpreter but not the non-interactive?

I greatly appreciate any thoughts,
Brian

[toc] | [next] | [standalone]


#19468

FromDevin Jeanpierre <jeanpierreda@gmail.com>
Date2012-01-25 22:04 -0500
Message-ID<mailman.5109.1327547136.27778.python-list@python.org>
In reply to#19465
On Wed, Jan 25, 2012 at 9:25 PM, Brian <brian.brinegar@gmail.com> wrote:
> Under what situations would a module be available to through the
> interactive interpreter but not the non-interactive?

I don't know if it matches your situation, but one such case is this:

The interactive interpreter (and the interpreter with the -c flag) add
the current working directory ('') to the module import search path
(sys.path). Regular python execution does not. So modules in the
current working directory can always be imported from the interactive
interpreter, but not necessarily if you run python on a source file.

-- Devin

[toc] | [prev] | [next] | [standalone]


#19481

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2012-01-26 11:58 +0100
Message-ID<mailman.5117.1327575523.27778.python-list@python.org>
In reply to#19465
Brian wrote:
> I've been banging my head against this for the past hour, and I'm
> hoping someone here can set me straight.
>
>   
[Snip]
> but, using the same same python, I'm able to import the module from
> the interactive interpreter. The PATH and PYTHONPATH environment
> variables are identical in both contexts.
>   
Are you sure ? with python 2.5, in interactive mode '' is happened to 
sys.path and is absent from it when a python file is executed.

python -c "import sys; print '' in sys.path"
True
python test.py
False

> Under what situations would a module be available to through the
> interactive interpreter but not the non-interactive?
>
> I greatly appreciate any thoughts,
> Brian
>   
As a more general notice, if you want to be able to import paste from 
everywhere, it must be properly installed as a python module.

Cheers,

JM

[toc] | [prev] | [next] | [standalone]


#19483

FromBrian Brinegar <brian.brinegar@gmail.com>
Date2012-01-26 07:47 -0500
Message-ID<mailman.5119.1327582029.27778.python-list@python.org>
In reply to#19465
JM,

Thanks for the response, you're correct '' is pre-pended to the path
in interactive mode. I've tried adding . to my PYTHONPATH and it
doesn't solve the problem.

When imported from interactive python the paste.deploy module is located at:

>>> import paste.deploy
>>> paste.deploy.__path__
['/home/brian/webapps/test_dyn/lib/python2.7/paste/deploy']

My path for both interactive and non-interactive contains:

/home/brian/webapps/test_dyn/lib/python2.7

>From the interactive interpreter I can import paste if my working
directory is inside of the.

/home/brian/webapps/test_dyn

Moving to a working directory above "test_dyn" point causes the import
to fail in the interactive interpreter as well.

I am able to import packages located the lib/python2.7/site-packages
directory of my virtualenv instance, but not the lib/python2.7
directory.

Thanks again,
Brian



On Thu, Jan 26, 2012 at 5:58 AM, Jean-Michel Pichavant
<jeanmichel@sequans.com> wrote:
> Brian wrote:
>>
>> I've been banging my head against this for the past hour, and I'm
>> hoping someone here can set me straight.
>>
>>
>
> [Snip]
>>
>> but, using the same same python, I'm able to import the module from
>> the interactive interpreter. The PATH and PYTHONPATH environment
>> variables are identical in both contexts.
>>
>
> Are you sure ? with python 2.5, in interactive mode '' is happened to
> sys.path and is absent from it when a python file is executed.
>
> python -c "import sys; print '' in sys.path"
> True
> python test.py
> False
>
>> Under what situations would a module be available to through the
>> interactive interpreter but not the non-interactive?
>>
>> I greatly appreciate any thoughts,
>> Brian
>>
>
> As a more general notice, if you want to be able to import paste from
> everywhere, it must be properly installed as a python module.
>
> Cheers,
>
> JM

[toc] | [prev] | [next] | [standalone]


#19488

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2012-01-26 14:49 +0100
Message-ID<mailman.5126.1327585770.27778.python-list@python.org>
In reply to#19465
Brian Brinegar wrote:
> JM,
>
> Thanks for the response, you're correct '' is pre-pended to the path
> in interactive mode. I've tried adding . to my PYTHONPATH and it
> doesn't solve the problem.
>
> When imported from interactive python the paste.deploy module is located at:
>
>   
>>>> import paste.deploy
>>>> paste.deploy.__path__
>>>>         
> ['/home/brian/webapps/test_dyn/lib/python2.7/paste/deploy']
>
> My path for both interactive and non-interactive contains:
>
> /home/brian/webapps/test_dyn/lib/python2.7
>
> From the interactive interpreter I can import paste if my working
> directory is inside of the.
>
> /home/brian/webapps/test_dyn
>
> Moving to a working directory above "test_dyn" point causes the import
> to fail in the interactive interpreter as well.
>
> I am able to import packages located the lib/python2.7/site-packages
> directory of my virtualenv instance, but not the lib/python2.7
> directory.
>
> Thanks again,
> Brian
>
>
>
> On Thu, Jan 26, 2012 at 5:58 AM, Jean-Michel Pichavant
> <jeanmichel@sequans.com> wrote:
>   
>> Brian wrote:
>>     
>>> I've been banging my head against this for the past hour, and I'm
>>> hoping someone here can set me straight.
>>>
>>>
>>>       
>> [Snip]
>>     
>>> but, using the same same python, I'm able to import the module from
>>> the interactive interpreter. The PATH and PYTHONPATH environment
>>> variables are identical in both contexts.
>>>
>>>       
>> Are you sure ? with python 2.5, in interactive mode '' is happened to
>> sys.path and is absent from it when a python file is executed.
>>
>> python -c "import sys; print '' in sys.path"
>> True
>> python test.py
>> False
>>
>>     
>>> Under what situations would a module be available to through the
>>> interactive interpreter but not the non-interactive?
>>>
>>> I greatly appreciate any thoughts,
>>> Brian
>>>
>>>       
>> As a more general notice, if you want to be able to import paste from
>> everywhere, it must be properly installed as a python module.
>>
>> Cheers,
>>
>> JM
>>     
Difficult to say without your PYTHONPATH value.

Assuming your PYTHONPATH is

/home/brian/webapps/test_dyn/lib/python2.7/site-packages

1/ paste is stable, copy the paste directory into 
/home/brian/webapps/test_dyn/lib/python2.7/site-packages
2/ paste is not stable, i.e. you're changing it from time to time, make 
a symbolic link to your dev paste directory within 
/home/brian/webapps/test_dyn/lib/python2.7/site-packages

you should now be able to import paste from anywhere.

JM


PS : please don't top post

[toc] | [prev] | [next] | [standalone]


#19491

FromBrian Brinegar <brian.brinegar@gmail.com>
Date2012-01-26 09:37 -0500
Message-ID<mailman.5128.1327588664.27778.python-list@python.org>
In reply to#19465
On Thu, Jan 26, 2012 at 8:49 AM, Jean-Michel Pichavant
<jeanmichel@sequans.com> wrote:
> Brian Brinegar wrote:
>>
>> JM,
>>
>> Thanks for the response, you're correct '' is pre-pended to the path
>> in interactive mode. I've tried adding . to my PYTHONPATH and it
>> doesn't solve the problem.
>>
>> When imported from interactive python the paste.deploy module is located
>> at:
>>
>>
>>>>>
>>>>> import paste.deploy
>>>>> paste.deploy.__path__
>>>>>
>>
>> ['/home/brian/webapps/test_dyn/lib/python2.7/paste/deploy']
>>
>> My path for both interactive and non-interactive contains:
>>
>> /home/brian/webapps/test_dyn/lib/python2.7
>>
>> From the interactive interpreter I can import paste if my working
>> directory is inside of the.
>>
>> /home/brian/webapps/test_dyn
>>
>> Moving to a working directory above "test_dyn" point causes the import
>> to fail in the interactive interpreter as well.
>>
>> I am able to import packages located the lib/python2.7/site-packages
>> directory of my virtualenv instance, but not the lib/python2.7
>> directory.
>>
>> Thanks again,
>> Brian
>>
>>
>>
>> On Thu, Jan 26, 2012 at 5:58 AM, Jean-Michel Pichavant
>> <jeanmichel@sequans.com> wrote:
>>
>>>
>>> Brian wrote:
>>>
>>>>
>>>> I've been banging my head against this for the past hour, and I'm
>>>> hoping someone here can set me straight.
>>>>
>>>>
>>>>
>>>
>>> [Snip]
>>>
>>>>
>>>> but, using the same same python, I'm able to import the module from
>>>> the interactive interpreter. The PATH and PYTHONPATH environment
>>>> variables are identical in both contexts.
>>>>
>>>>
>>>
>>> Are you sure ? with python 2.5, in interactive mode '' is happened to
>>> sys.path and is absent from it when a python file is executed.
>>>
>>> python -c "import sys; print '' in sys.path"
>>> True
>>> python test.py
>>> False
>>>
>>>
>>>>
>>>> Under what situations would a module be available to through the
>>>> interactive interpreter but not the non-interactive?
>>>>
>>>> I greatly appreciate any thoughts,
>>>> Brian
>>>>
>>>>
>>>
>>> As a more general notice, if you want to be able to import paste from
>>> everywhere, it must be properly installed as a python module.
>>>
>>> Cheers,
>>>
>>> JM
>>>
>
> Difficult to say without your PYTHONPATH value.
>
> Assuming your PYTHONPATH is
>
> /home/brian/webapps/test_dyn/lib/python2.7/site-packages
>
> 1/ paste is stable, copy the paste directory into
> /home/brian/webapps/test_dyn/lib/python2.7/site-packages
> 2/ paste is not stable, i.e. you're changing it from time to time, make a
> symbolic link to your dev paste directory within
> /home/brian/webapps/test_dyn/lib/python2.7/site-packages
>
> you should now be able to import paste from anywhere.
>
> JM
>
>
> PS : please don't top post

JM,

Thanks so much for all of your help. I added a symlink in
site-packages and it still did not work. Upon further investigation I
found that the there wasn't an __init__.py in the paste or
paste/deploy directories. Creating python2.7/paste/__init__.py and
python2.7/paste/deploy/__init__.py fixed the issue without a need for
the symlink.

I'm curious why the interactive interpreter is able to import this
without the proper package structure.

Thanks again for your help,
Brian

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web