2014-04-18 158 views
1

我已經能夠運行我從IDE寫入瓶中的Web應用程序。它運行良好,當我試圖將它移動到一個新的系統時,它打破了(找不到我在lib文件夾中寫入的文件)。Python無法找到我的軟件包:

如何找到我的lib文件?我發現這對瓶:

bottle.TEMPLATE_PATH.insert(0,'/absolut/path/to/templates/') 

而且我認爲,這將與丟失.tpl文件的幫助,但我怎麼一般這樣做的蟒蛇?我可以在main.py中添加某種python.PATH.insert()嗎?

這裏是我的目錄結構:

DEV 
├───.idea 
│ ├───inspectionProfiles 
│ └───scopes 
└───myProject *(Also has a .py file I need)* 
    ├───output 
    │ └───processed 
    └───webapp 
     ├───src 
     │ ├───lib 
     │ │ └───*(All my .py files I need)* 
     │ ├───static 
     │ │ ├───css 
     │ │ ├───files 
     │ │ ├───img 
     │ │ └───js 
     │ └───views *(All the .tpl files I need)* 
     │  ├───main 
     │  ├───popup 
     │  └───reports 
     └───main.py *(The file that acesses the .py files)* 

相關代碼:

import threading 
import time 
import datetime 

import crud_ops 
from helper_functions import load_config_file, dt_ona_sum_format 
from server import run_bottle 
from myProject import ona_sum_tool #THIS LINE HERE 

... 


def run_queue(col): 

    while(1): 
     if not col: 
      print "Unable to connect to db." 
     else: 
      my_limit = 10 
      processing_cursor = col.queue.find({"status":"processing"}).limit(my_limit) 
      if not processing_cursor.count(): 
       queued_cursor = col.queue.find({"status":"queued"}).limit(my_limit) 
       if queued_cursor.count(): 
        for doc in queued_cursor: 
         print col.queue.update({"_id":doc['_id']},{"$set":{"status":"processing"}}) 
       # print col.queue.update({"status":"queued"}, {"$set":{"status":"processing"}}).limit(10) 
        processing_cursor = col.queue.find({"status":"processing"}) 
      if processing_cursor.count(): 
       time.sleep(1) 
       for doc in processing_cursor: 
        ############################# THIS LINE HERE ###################### 
        new_file_name = ona_sum_tool.run_summary(dt_ona_sum_format(doc['start']), dt_ona_sum_format(doc['end'])) 
        # print "new_file_name: ", new_file_name 
        old_id = doc['_id'] 
        # print old_id 
        doc['_id'] = str(new_file_name) 
        doc['status'] = 'done' 

        insert_result = col.queue.insert(doc) 
        if(insert_result): 
         col.queue.remove({"_id":old_id}) 

錯誤:

Traceback (most recent call last): 
    File "main.py", line 5, in <module> 
    from lib.threads import ConnectToDBThread, StartBottleThread, ProcessOutputController, \ 
    File "C:\dev\myProject\myProject\webapp\src\lib\threads.py", line 10, in <module> 
    from myProject import ona_sum_tool 
ImportError: No module named onager 

回答

3

也許你已經忘了放了__init__.py文件在您lib文件夾。 Here's why you need the __init__.py file

The init.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, init.py can just be an empty file, but it can also execute initialization code for the package or set the all variable, described later.

+0

我有我的lib文件夾中的文件。我還在其他幾個文件夾中...可能是一個問題嗎? – Jeff

+0

如果你想從'main.py'訪問'lib'文件夾中的文件,那麼你的'src'文件夾也需要'__init __。py'文件。我不知道所有其他'__init.py'文件在哪裏,但不應該是問題。 – s16h

+0

也許編輯你的問題來顯示'main.py'中的相關代碼以及你得到的錯誤。 – s16h

相關問題