让用户定义的包在WindowsPython2.7中工作

2024-04-24 23:33:39 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我似乎能够从库(站点)的顶层导入_康斯特斯比)但不是子文件夹:

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
>>>

我错过了什么?你知道吗


Tags: inpy文件夹webbytesislibdir