2014-04-18 3 views
1

IDE에서 병에 쓴 웹 응용 프로그램을 실행할 수있었습니다. 그것은 잘 작동하고 새로운 시스템으로 옮기려고했을 때 lib 폴더에 쓴 파일을 찾을 수 없었습니다.파이썬에서 내 패키지를 찾을 수 없습니다.

어떻게하면 내 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

아마 당신이 당신의 lib 폴더하여 __init__.py 파일을 넣어 잊어 버린 . 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'에서'lib' 폴더에있는 파일에 접근하고 싶다면'src' 폴더에'__init __. py' 파일이 있어야합니다. 나는 다른 모든'__init.py' 파일이 어디에 있는지 확실하지 않지만 어쨌든 문제가되어서는 안된다. – s16h

+0

질문을 편집하여 관련 코드를'main.py'에 표시하면 오류가 발생할 수 있습니다. – s16h

관련 문제