0

I want to upload a flask server to bluemix. The structure of my project is something like this

  • Classes
    • functions.py
  • Watson
    • bot.py
  • requirements.txt
  • runtime.txt
  • Procfile
  • manifest.yml

my bot.py has this dependency:

from classes import functions

I have tried to include it in the manifest using things like this:
./classes or ./classes/functions

but I have had no luck, it keeps saying either that module is not found or things like pip.exceptions.InstallationError: Invalid requirement: './classes/functions'

I dont know how to add the dependency

manifest.yml

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

Procfile (the file that I use to run the app)

web: python watson/bot.py

when I print my sys.path I get this:

    ['..', '/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']

I have tried to add the folder parent to my script using

Thanks a lot for your help!!!

Kailegh
  • 199
  • 1
  • 13

2 Answers2

1

You don't need to include it into the manifest file. Your entire app directory and its subdirectories are uploaded as part of the push command. Thereafter, it is possible to reference the file as shown.

This imports a file in the current directory:

import myfile

This should work for your functions.py:

from classes import functions
data_henrik
  • 16,724
  • 2
  • 28
  • 49
  • ok, i have edited my question, what I actually do is: from classes import functions but it does not work, I have realized that changing bot.py to the root folder makes everything works, but that is not what I want, I would like to be able to run it from the watson folder – Kailegh Jun 05 '18 at 07:26
  • How do you start bot.py? How does your manifest.yml look like? Also see this https://stackoverflow.com/questions/714063/importing-modules-from-parent-folder – data_henrik Jun 05 '18 at 07:36
0

Thanks a lot, this finally worked for me, the answered you pointed me to gave me the solution, thanks a lot again!

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)
Kailegh
  • 199
  • 1
  • 13