execute python script question

Gabriel Rossetti gabriel.rossetti at mydeskfriend.com
Tue Mar 11 04:49:18 EDT 2008


Sam wrote:
> Hello,
>
> I may misunderstand your problem, but it may be related to the
> execution environment, especially the PYTHONPATH variable. Have a look
> at the following log:
>
> samuel at Bioman2:/$ pwd
> /
> samuel at Bioman2:/$ cat -n /tmp/test_import.py
>      1  class A(object):
>      2      def __init__(self):
>      3          self.value = 1
>      4      def show(self):
>      5          print self.value
> samuel at Bioman2:/$ python
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:50:07)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>   
>>>> from test_import import A
>>>>         
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ImportError: No module named test_import
>   
>>>> exit()
>>>>         
> samuel at Bioman2:/$ export PYTHONPATH=/tmp
> samuel at Bioman2:/$ python
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:50:07)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>   
>>>> from test_import import A
>>>> a=A()
>>>> a.show()
>>>>         
> 1
>   
>
> ++
>
> Sam
>   
Hello Sam,

Thank you for your reply. I tried that and it works, thanks. I was 
trying to modify the sys.path in __init__.py and it wasn't working.

Gabriel



More information about the Python-list mailing list