0

我已经阅读了关于包的参考页面,但我似乎无法从我的库文件夹中导入模块。这是我的图书馆:

K:\web\cgi\lib>dir
 Volume in drive K is Krusty
 Volume Serial Number is E889-7AE2

 Directory of K:\web\cgi\lib

16/12/2012  07:52    <DIR>          .
16/12/2012  07:52    <DIR>          ..
16/12/2012  07:52    <DIR>          database
16/12/2012  07:21    <DIR>          kmz_builder
16/12/2012  05:45                21 site_consts.py
16/12/2012  07:42                 0 __init__.py
           2 File(s)             21 bytes
           4 Dir(s)  267,263,594,496 bytes free

这是数据库文件夹:

 K:\web\cgi\lib>dir database
 Volume in drive K is Krusty
 Volume Serial Number is E889-7AE2

 Directory of K:\web\cgi\lib\database

16/12/2012  07:52    <DIR>          .
16/12/2012  07:52    <DIR>          ..
13/12/2012  01:52             3,643 dbops.py
12/12/2012  12:49            11,414 dbspec.py
08/12/2012  11:30             4,104 MyDB.py
               3 File(s)         19,161 bytes
               2 Dir(s)  267,263,594,496 bytes free

设置环境变量:

K:\web\cgi\lib>echo %PYTHONPATH%
k:\web\cgi\lib

我似乎可以从库的顶层(site_consts.py)导入,但不能从子文件夹导入:

K:\web\cgi\lib>python
ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
Python 2.7.1 (r271:86832, Feb  7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on
Type "help", "copyright", "credits" or "license" for more information.
>>> import site_consts
>>> import database.dbspec
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named database.dbspec
>>>

请问我错过了什么?

4

1 回答 1

0

__init__.py尝试在目录中创建一个名为的空白文件database。该__init__.py文件告诉 Python 该目录应该被视为一个

于 2012-12-16T08:16:44.887 回答