Bluemix的Local dependencies requerients.txt

2024-04-28 07:39:15 发布

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

我想上传一个flask服务器到bluemix。我的项目结构是这样的

  • 班级
    • 函数.py
  • 沃森
    • bot.py公司
  • 要求.txt
  • 运行时.txt
  • 程序文件
  • 清单.yml

我的bot.py具有以下依赖关系:

from classes import functions

我尝试使用以下方式将其包含在清单中:
./classes或./classes/函数

但我运气不好,它一直说要么模块找不到,要么像pip.exceptions.InstallationError:Invalid requirement:“./classes/functions”

我不知道如何添加依赖项

清单.yml

---
applications:
- name: chatbotstest
  random-route: true
  memory: 256M

Procfile(我用来运行应用程序的文件)

web: python watson/bot.py

当我打印sys.path时,我得到:

    ['..', '/home/vcap/app/watson', '/home/vcap/deps/0/python/lib/python36.zip', '/home/vcap/deps/0/py
e/vcap/deps/0/python/lib/python3.6/lib-dynload', '/home/vcap/deps/0/python/lib/python3.6/site-packages', '/home/vcap/deps/0/python/lib/python3.6/site-
-py3.6.egg', '/home/vcap/deps/0/python/lib/python3.6/site-packages/pip-9.0.1-py3.6.egg']

我尝试使用将父文件夹添加到脚本中

非常感谢你的帮助


Tags: pip文件函数depspytxthomelib
2条回答

非常感谢,这终于为我工作了,你指给我的答案给了我解决方案,再次感谢

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)

您不需要将其包含到清单文件中。整个应用程序目录及其子目录将作为push命令的一部分上载。此后,可以参照如图所示的文件

这将导入当前目录中的文件:

import myfile

这应该适用于functions.py

from classes import functions

相关问题 更多 >