【问题标题】:Local dependencies requeriments.txt for Bluemix serverBluemix 服务器的本地依赖项 requirements.txt
【发布时间】:2018-06-04 16:48:48
【问题描述】:

我想将烧瓶服务器上传到 bluemix。我的项目结构是这样的

    • functions.py
  • 沃森
    • bot.py
  • requirements.txt
  • runtime.txt
  • 过程文件
  • manifest.yml

我的 bot.py 有这个依赖:

from classes import functions

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

但我没有运气,它一直说找不到模块或 pip.exceptions.InstallationError: Invalid requirements: './classes/functions' 之类的东西

不知道怎么添加依赖

manifest.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']

我尝试使用

将文件夹父级添加到我的脚本中

非常感谢您的帮助!!!

【问题讨论】:

    标签: python flask pip ibm-cloud requirements


    【解决方案1】:

    您无需将其包含在清单文件中。您的整个应用程序目录及其子目录作为push 命令的一部分上传。此后,可以如图所示引用该文件。

    这会在当前目录中导入一个文件:

    import myfile
    

    这应该适用于您的functions.py

    from classes import functions
    

    【讨论】:

    • 好的,我已经编辑了我的问题,我实际上做的是:从类导入函数但它不起作用,我意识到将 bot.py 更改为根文件夹可以使一切正常,但是不是我想要的,我希望能够从 watson 文件夹中运行它
    • 如何启动 bot.py?您的 manifest.yml 看起来如何?另见stackoverflow.com/questions/714063/…
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-08
      • 2016-10-24
      • 1970-01-01
      • 2014-07-21
      • 2019-06-02
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      相关资源
      最近更新 更多