gpt4 book ai didi

Python 找不到我的包 :

转载 作者:行者123 更新时间:2023-11-30 23:25:00 25 4
gpt4 key购买 nike

我已经能够从 IDE 运行我在 Bottle 中编写的 Web 应用程序。它工作得很好,当我尝试将它移动到新系统时,它坏了(找不到我在 lib 文件夹中编写的文件)。

如何让它找到我的 lib 文件?我找到了这个瓶子:

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

我认为这将有助于解决丢失的 .tpl 文件,但一般来说我该如何为 python 做到这一点?我可以在 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

最佳答案

也许您忘记将 __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.

关于Python 找不到我的包 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com