473,671 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import - interpreter works but .py import does not

First post and very much a newbie to Python. Have 2.5 on Linux (GG). I
think I have set up PYTHONPATH correctly in that I can import a module
apply_bp and it complains about line 20 in apply_bp which is:

import sys, aipy, numpy, os

At the interpreter prompt, however, I can import sys, numpy etc. and
can do dir() and see the entry points so I think my overall
installation is OK.

Why does line not work ? Also I would have thought that when I pre-
imported sys et al that they would be in the symbol table so that the
import line would be a noop.

Thanks,

Slainte,

John
Mar 10 '08 #1
1 1831
On Mar 10, 1:59 pm, John Boy <sla1nte2...@ya hoo.comwrote:
First post and very much a newbie to Python. Have 2.5 on Linux (GG). I
think I have set up PYTHONPATH correctly in that I can import a module
apply_bp and it complains about line 20 in apply_bp which is:

import sys, aipy, numpy, os
Please get used to showing the error message. "it complains about line
x" is not very helpful. Fortunately in this case we can guess that it
is "complainin g" about inability to import either aipy or numpy (sys
and os are built-in).
>
At the interpreter prompt, however, I can import sys, numpy etc. and
can do dir() and see the entry points so I think my overall
installation is OK.

Why does line not work ?
More information please.

At the interpreter prompt, do this:
import sys
sys.path
import aipy; aipy.__file__
import numpy; numpy.__file__
and show us the result.
Change the offending line in your apply_bp module to
import sys
print sys.path
import os, aipy, numpy
and show us ALL of the output.
At the shell prompt, do whatever it takes to display the contents of
PYTHONPATH, and show us the results.
Also I would have thought that when I pre-
imported sys et al that they would be in the symbol table so that the
import line would be a noop.
The concept of "preimporti ng" a module is novel to me. Importing a
module at the interpreter prompt doesn't persist when you exit the
interpreter and then (implicitly) start up another interpreter task to
run your script. Importing a module in your script puts the module in
the script's namespace, which is quite distinct from the namespace of
the apply_bp (or any other) module. If those two possibilities don't
cover what you mean, please explain.
Mar 10 '08 #2

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

Similar topics

5
1818
by: Colin Brown | last post by:
I have instances where Python 2.3.2 import both does not work or error. It can be demonstrated under Win2k and Linux by doing the following: 1. Create a subdirectory "abc" 2. In directory "abc" create a blank "__init__.py" 3. In directory "abc" create a file "abc.py" containing "print 'this is abc'" 4. Interactively run python interpreter >>> import sys >>> sys.path.append('./abc')
0
2574
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of wxGetFreeMemory()". Since wxGetFreeMemory() seemed effectively unused in gtk, I just commented it out in misc_wrap.cpp (didn't want to patch SWIG to regenerate the wrapper code, so hacked the generated cpp source), and replaced...
2
16787
by: Wolfgang.Stoecher | last post by:
Hi, another beginner's question: when I import a module, change the corresponding textfile and try to import the same module again, it looks like the internal code does not change (the source-line in an error-message is up to date, however!). Also del module before import and deleting the .pyc file do not help! How to realize a fast edit-try-cycle? (btw: I am using python 2.2 under windows) thanks in advance!
3
1772
by: Olivier Noblanc ATOUSOFT | last post by:
Hello, When i want to import a .py fire from another subdirectory i make import inc/setupxml but that make me an error message.
0
2711
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the latter contains the line "import _SHIP". I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
11
2109
by: Mark | last post by:
Hello I made a site with validated XHTML and CSS. It works fine also. Only in IE i see the site build up without CSS (very fast though) and then the CSS is used to build the page. When i use this it works fine: <link href="styles/site.css" rel="stylesheet" type="text/css" />
7
2749
by: per9000 | last post by:
Dear Black Knight, I have no quarrel with you sir Knight, but I must import your parents. SHORT VERSION: I tried three variants of "from ../brave.py import sir_robin", one works. I want to use it in a py-file to execute command-line-style and that does not work.
49
3914
by: Martin Unsal | last post by:
I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the isomorphism between filesystem and namespace, doesn't seem very well suited for big projects. However, I might not really understand the Pythonic way. I'm not sure if I have a specific question here, just a general plea for advice. 1) Namespace....
8
1114
by: jmDesktop | last post by:
Hi, I have this code (learning from Core Python, Chun's book), module named chap2.py. class FooClass(object): version=0.1 def __init__(self, nm='John Doe'): self.name=nm print 'Created a class instance for ', nm def showname(self):
0
8481
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
8924
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
8823
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8672
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
5702
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
4412
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1814
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.