473,416 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Why do I get an import error on this?

I'm trying to run a Python program on Unix and I'm encountering some
behavior I don't understand. I'm a Unix newbie, and I'm wondering if
someone can help.

I have a simple program:
____________________________________________

#! /home/fergs/python/bin/python
import sys, os
import cx_Oracle
____________________________________________

If I run it through the Python interpreter, this way:
python test.py
it runs fine.

But if I try to run it as an executable script, this way:
test.py


I get an import error that says it can't find cx_Oracle.

Why does it behave differently when I run it in these two ways, and
what do I need to do to make it run successfully either way?

Oct 7 '05 #1
4 1768
Steve wrote:
I'm trying to run a Python program on Unix and I'm encountering some
behavior I don't understand. I'm a Unix newbie, and I'm wondering if
someone can help.

I have a simple program:
____________________________________________

#! /home/fergs/python/bin/python
import sys, os
import cx_Oracle
____________________________________________

If I run it through the Python interpreter, this way:
>> python test.py
it runs fine.

But if I try to run it as an executable script, this way:
>> test.py


I get an import error that says it can't find cx_Oracle.

Why does it behave differently when I run it in these two ways, and
what do I need to do to make it run successfully either way?


I ran across something similar with using py2exe. I think it occurs
when there are more than one file with the same name in different
locations in the search path. Try renaming cx_Oracle to _cx_Oracle then
import as...

import _cx_Oracle as cx_Oracle

Of course your problem might be entirely different. But this might help.

Cheers,
Ron

Oct 7 '05 #2
On Oct 07, Steve wrote:
I have a simple program:
____________________________________________

#! /home/fergs/python/bin/python
import sys, os
import cx_Oracle
____________________________________________

If I run it through the Python interpreter, this way:
>> python test.py
it runs fine.

But if I try to run it as an executable script, this way:
>> test.py


I get an import error that says it can't find cx_Oracle.


Are "which python" and "/home/fergs/python/bin/python" the same? If
not, it appears that "which python" can see cx_Oracle, but the latter
cannot. You could mess with PYTHONPATH or get /home/.../python into the
front of your PATH.

--
Micah Elliott
<md*@micah.elliott.name>
Oct 7 '05 #3
"Steve" wrote:
I'm trying to run a Python program on Unix and I'm encountering some
behavior I don't understand. I'm a Unix newbie, and I'm wondering if
someone can help. If I run it through the Python interpreter, this way:
>> python test.py
it runs fine.

But if I try to run it as an executable script, this way:
>> test.py


I get an import error that says it can't find cx_Oracle.

Why does it behave differently when I run it in these two ways, and
what do I need to do to make it run successfully either way?


in the first case, the shell uses the PATH variable to search for a python
interpreter. in the second case, the shell uses the path specified in the
script.

what does "which python" say?

</F>

Oct 7 '05 #4
I did "which python" and the two paths were different. Once I fixed
the path in the script, it worked fine.

Thanks Frederik and Micah!

Oct 7 '05 #5

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

Similar topics

2
by: Markus Doering | last post by:
Hello, I just switched from 2.2 to Python 2.3. I am developing an XML/CGI interface to databases as a python package called "unitWrapper" containing several modules which ran fine under v2.2. ...
1
by: jean.rossier | last post by:
Hello All, I am facing a problem while importing pylab library(in a .py program file) via web browser however the same program works when I execute it from the command prompt. my...
0
by: zhang xiaoning | last post by:
Hi, I download and extract python-2.4.2 source code for unix, and then, build and install it on aix5, the configure option I used is: ../configure --enable-shared --disable-ipv6...
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
1
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
3
by: Neter Smith | last post by:
I have run into a problem when trying to import a WSDL reference under VS 2003 and 1.1 of the framework. It appears as if it is in the generation of the proxy that things are failing. When I...
4
by: Mathias Waack | last post by:
Hi, I've embedded python into a legacy application. It works - most of the time. In some special situations the app crashes executing the "import random". There are two different situations: ...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
2
by: KingoftheKings | last post by:
I'm new here. I want a help with VB codes that will import text or excel files from a specified directory in to an existing or new Access table. I have written some codes, but when I click the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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...

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.