473,750 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ImportError raised in script, not interactive session.

I'm writing a set of modules to monitor remote system services, and I'm
having a problem running my test scripts. When I pass the scripts into
python, like so:

--
$ PYTHONPATH="${T ARGET_DIR}" python test.py
--

I get an ImportError:

--
Traceback (most recent call last):
File "./test.py", line 6, in ?
from overwatch.view import console
ImportError: No module named view
--

However, when I load up an interactive Python session:

--
$ PYTHONPATH="${T ARGET_DIR}" python
--

I can do the exact same import statement with no problem:

--
Python 2.4.3 (#1, Jul 28 2006, 09:40:08)
[GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>from overwatch.view import console
dir(console )
['Daemon', 'UI', '__builtins__', '__doc__', '__file__', '__name__',
'datetime']
--

My package directory is arranged under ${TARGET_DIR} as prescribed in
the Python docs:
overwatch/
...__init__.py
...[etc.]
...view/
.....__init__.p y
.....console.py
.....[etc.]

All modules involved are my own, and I'm setting PYTHONPATH so I can
test with the package installed in my home directory (which I use
distutils to do). I've checked online, and double-checked the Python
docs to make sure my modules are arranged properly, and it all looks
alright. Any ideas?

Jul 31 '06 #1
2 2181
Assuming your setting the target directory to the overwatch folder, and you are starting the interactive session in your home directory, this is what is happening. The folder containing your package must be in the python path, not the folder itself. Try "PYTHONPATH =/home/directory python test.py". The reason it works in the interactive session, assuming you are starting it from your home directory, is that the current directory of the session is placed at the front of the import path; the value of PYTHONPATH is merely added after the current directory, and before the standard directories.

If this isn't the case, what are you using for TARGET_DIR?

Jordan

-----Original Message-----
From: py************* *************** *************** @python.org on behalf of Adam Blinkinsop
Sent: Mon 7/31/2006 5:42 PM
To: py*********@pyt hon.org
Subject: ImportError raised in script, not interactive session.

I'm writing a set of modules to monitor remote system services, and I'm
having a problem running my test scripts. When I pass the scripts into
python, like so:

--
$ PYTHONPATH="${T ARGET_DIR}" python test.py
--

I get an ImportError:

--
Traceback (most recent call last):
File "./test.py", line 6, in ?
from overwatch.view import console
ImportError: No module named view
--

However, when I load up an interactive Python session:

--
$ PYTHONPATH="${T ARGET_DIR}" python
--

I can do the exact same import statement with no problem:

--
Python 2.4.3 (#1, Jul 28 2006, 09:40:08)
[GCC 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)] on linux2
Type "help", "copyright" , "credits" or "license" for more information.
>>from overwatch.view import console
dir(console )
['Daemon', 'UI', '__builtins__', '__doc__', '__file__', '__name__',
'datetime']
--

My package directory is arranged under ${TARGET_DIR} as prescribed in
the Python docs:
overwatch/
...__init__.py
...[etc.]
...view/
.....__init__.p y
.....console.py
.....[etc.]

All modules involved are my own, and I'm setting PYTHONPATH so I can
test with the package installed in my home directory (which I use
distutils to do). I've checked online, and double-checked the Python
docs to make sure my modules are arranged properly, and it all looks
alright. Any ideas?

--
http://mail.python.org/mailman/listinfo/python-list
Jul 31 '06 #2
Jordan R McCoy wrote:
If this isn't the case, what are you using for TARGET_DIR?
${TARGET_DIR} = /home/blinks/projects/overwatch/target/lib/python
I've started the interactive session from several different
directories, and never had a problem.

My make output (note the second item in sys.path):
--
cd /home/blinks/projects/overwatch/target/bin &&
PYTHONPATH="/home/blinks/projects/overwatch/target/lib/python"
../test.py
*** sys.path: ['/home/blinks/projects/overwatch/target/bin',
'/home/blinks/projects/overwatch/target/lib/python',
'/usr/lib/python24.zip', '/usr/lib/python2.4',
'/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk',
'/usr/lib64/python2.4/lib-dynload', '/usr/lib/portage/pym',
'/usr/lib64/python2.4/site-packages',
'/usr/lib/python2.4/site-packages']
Traceback (most recent call last):
File "./test.py", line 6, in ?
from overwatch.view import console
ImportError: No module named view
make: *** [test] Error 1
--

Oh, and:
--
$ ls /home/blinks/projects/overwatch/target/lib/python/
overwatch
--

Thanks for the help! If you want a copy of the project to reproduce,
it's on Subversion at http://tools.assembla.com/svn/Overwatch/trunk
(should be readable).

Jul 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17714
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
2
6771
by: Chris Hodapp | last post by:
I have seen messages posted about this before, and there is a clear reference to it in the manual, but I have been unable to find a solution. I'm on Slackware 9.1, kernel 2.6.0-test11, using Python 2.3.1 and GCC 3.2.3 (both installed by default with Slackware) and SWIG 1.3.19, compiled from source code. I messed around a little on my own and couldn't get things to work right, so I copied the examples from the book, nearly verbatim but...
4
1550
by: cepl | last post by:
Is there anything like script(1) for python interactive sessions. From script(1) manpage: Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved...
7
1868
by: Bo Peng | last post by:
Dear list, I have a long list of commands in the form of a script and would like to obtain a log file as if I enter the commands one by one. (The output will be used in a tutorial.) What would be the best way to do it? Copy and paste is not acceptable since I make frequent changes tot he script. Many thanks in advance. Bo
3
3967
by: mirandacascade | last post by:
Verion of Python: 2.4 O/S: Windows XP ElementTree resides in the c:\python24\lib\site-packages\elementtree\ folder When a string that does not contain well-formed XML is passed as an argument to the XML() method in ElementTree.py, an ExpatError exception is raised. I can trap the exception with a try/except where the except does not specify a specific exception, but I cannot figure out how to construct the except clause in a...
8
5879
by: TS | last post by:
Im in a web page and call an asynchronous method in business class. the call back method is in the web page. When page processes, it runs thru code begins invoking the method then the page unloads. When the callback method is raised, only the method in the web page is run and the page never refreshes, it seems it all happens on the server side. I am trying to refresh the constrols on the page inside the callback method, but when id...
3
24333
by: gmax2006 | last post by:
Hi, I am using RedHat Linux 4. and I developed an oracle 10g based application by using cx_Oracle (cx_Oracle-4.1-10g-py23-1.i386.rpm) and Python 2.3.4. When I run the application through direct console connection, It works perfect. But, when I schedule a crontab job to run the application, It logs this
3
3363
by: Tim | last post by:
I'm at the end of my limited experience... I'm using py2exe to create an executable. I'm using bundle level 1. When I don't use the zipfile option, the executable and library.zip get created and the executable works correctly. When I add the zipfile=None option to put everything into the exe, the exe doesn't work. It raises an ImportError whose traceback is: File "...boot_common.py" ... no module name linecache
13
4005
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks, asynchronously. These tasks might take long time so I want to keep the user informed of the progress. The problem is that only the PHP script knows the progress, how can the web page gets these information from PHP script?
0
9000
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.