Re: Problems with import

2007-12-04 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 Hi,
 
 I have some problems when importing a library. Suppose I have a
 directory /home/user/pythonlib/package in which I have a python-
 library called test.py. Now I want to import that, so I put the
 following directory into the PYTHONPATH: /home/user/pythonlib and in
 my main python script I put:
 
 from package import test.
 
 BUT I get an error:
 
 ImportError: cannot import name test
 
 So how can I test and check what is going on, why python does not find
 the library?

Do you have this directory structure?

package/__init__.py
test.py


Only then (with the __init__.py in place, it can be empty) package will be
recognized as such.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with import

2007-12-04 Thread Alexander Dietz
Aaah,

this it it! Thank you very much...

Alex

On Dec 4, 2007 11:49 AM, Diez B. Roggisch [EMAIL PROTECTED] wrote:

 [EMAIL PROTECTED] wrote:

  Hi,
 
  I have some problems when importing a library. Suppose I have a
  directory /home/user/pythonlib/package in which I have a python-
  library called test.py. Now I want to import that, so I put the
  following directory into the PYTHONPATH: /home/user/pythonlib and in
  my main python script I put:
 
  from package import test.
 
  BUT I get an error:
 
  ImportError: cannot import name test
 
  So how can I test and check what is going on, why python does not find
  the library?

 Do you have this directory structure?

 package/__init__.py
test.py


 Only then (with the __init__.py in place, it can be empty) package will be
 recognized as such.

 Diez
 --
 http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Problems with import of modules

2006-01-26 Thread Ilias Lazaridis
the sys.path.append has done the work.

thanks.

.

-- 
http://lazaridis.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with import of modules

2006-01-23 Thread Farshid Lashkari
 How can I modify the python search-path from within the script, thus it 
 contains the doc directory?

Hi,

The sys.path variable is a list of strings that contains the current 
module search path. You can add your own path to this list:

import sys
sys.path.append('../')

-Farshid
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with import of modules

2006-01-23 Thread Carl J. Van Arsdall
Ilias Lazaridis wrote:
 I am within a directory

 \doc\template\

 I launch script.py

 within this script.py, I like to import a module from the doc directory.

 this here does not work:

 form ..\..\module_name import this_one
   
Well, if you are in linux you can do this easily by changing your 
PYTHONPATH environment variable, either by changing it explicitely or by 
editing it in your .rc files to append the /doc directory.

Although I don't know specifically where this variable might be if you 
are using windows, in either case(windows or linux), you can alter this 
from python using sys.path

import sys
sys.path.append(/doc)

Hope that helps,

-carl

 how do I go back in the directory hierarchy to import something?

 If this is not possible:

 How can I modify the python search-path from within the script, thus it 
 contains the doc directory?

 .

   


-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

-- 
http://mail.python.org/mailman/listinfo/python-list