473,382 Members | 1,332 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,382 software developers and data experts.

Why canNOT import from a local directory ?

Hi all

I created a folder named *lib* and put a py file *lib.py* in it.
In the upper folder I created a py file as:

<CODE>
import lib.lib

def main():
"""
__doc__
"""
lib.lib.test()
# ////////////////////////////////////////
if __name__ == "__main__":
main()
But I got an error :
#.:python main.py
Traceback (most recent call last):
File "main.py", line 6, in ?
import lib.lib
ImportError: No module named lib.lib

Why ?

May 18 '07 #1
2 1098
Jia Lu wrote:
Hi all

I created a folder named *lib* and put a py file *lib.py* in it.
In the upper folder I created a py file as:

<CODE>
import lib.lib

def main():
"""
__doc__
"""
lib.lib.test()
# ////////////////////////////////////////
if __name__ == "__main__":
main()
But I got an error :
#.:python main.py
Traceback (most recent call last):
File "main.py", line 6, in ?
import lib.lib
ImportError: No module named lib.lib

Why ?
You need to define a file __init__.py in your newly created lib directory.

HTH
Thin

May 18 '07 #2
>
You need to define a file __init__.py in your newly created lib directory.
Thank you very much :)
May 18 '07 #3

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

Similar topics

4
by: Irmen de Jong | last post by:
Hello, I don't understand why the following doesn't work. What I want to do is dynamically import some generated Python code and I'm doing this using compile and exec'ing it in the dict of a new...
1
by: yazzoo | last post by:
I've been banging my head over a long running script that has suddenly stopped working when my ISP upgraded Apache and Suexec. They didn't specify what they did, but I presume it was the latest...
7
by: Eric Belanger | last post by:
Hi, Before posting I made sure I upgraded from 2.3.3 to 2.3.4, but the problem is still here. Ive created a little script which, at the end of it, deals with copying two files. All the script...
6
by: John J. Lee | last post by:
I'm tearing my hair out at what seems like weird import behaviour I'm getting from Python's stdlib test script, regrtest.py (not for the first time: seem to have forgotten the resolution from last...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
19
by: Michael | last post by:
Hi, I'm trying to do something which should be very simple - connect to the MySQL database. Here is the call, followed by the error msg. $conn = mysql_connect("localhost", "root", ""); ...
2
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made...
10
by: Jia Lu | last post by:
Hi all: I try to do things below: import i Traceback (most recent call last): File "<pyshell#67>", line 2, in <module> import i ImportError: No module named i But it seems that import...
0
by: Alan Isaac | last post by:
This is really a repackaging of an earlier question, probably illustrating that I still do not understand relative imports. Suppose I have the package structure (taken from the example at...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.