0

So I have a path structure that looks like this:

~/Dropbox/Coding/Python/Chessbotslack/scripts/Flask_interface.py
~/Dropbox/Coding/Python/Chessbotslack/database/spreadsheets.py

The first line of the Flask_interface.py is:

from Chessbotslack.database.spreadsheets import add_game

If I run this from my IDE (PyCharm) it runs just fine; but if I run it from my terminal it throws the error:

Traceback (most recent call last):
  File "Flask_interface.py", line 1, in <module>
    from Chessbotslack.database.spreadsheets import add_game
ModuleNotFoundError: No module named 'Chessbotslack'

To solve this I did two things:

1) Adding __init__.py to the directories

This did seem to accomplish anything

2) Adding the directory to $PYTHONPATH

In terminal I ran

export PYTHONPATH=$PYTHONPATH:~/Dropbox/Coding/Python

This solved the problem for running it from my terminal, but as expected it did not solve it for my IBM-Cloud. Perhaps it has something to do with the requirements.txt file?

2018-04-16T09:08:45.30+0200 [APP/PROC/WEB/0]ERR   File "scripts/Flask_interface.py", line 1, in <module>
2018-04-16T09:08:45.30+0200 [APP/PROC/WEB/0]ERR     from Chessbotslack.database.spreadsheets import add_game
2018-04-16T09:08:45.30+0200 [APP/PROC/WEB/0]ERR ImportError: No module named Chessbotslack.database.spreadsheets
Herman
  • 320
  • 2
  • 16

1 Answers1

0

Changing to a flat folder structure (every file in the Chessbotslack folder) and changing the import command from:

from Chessbotslack.database.spreadsheets import add_game

to:

from spreadsheets import add_game

solved it. The weird thing is that the IDE (PyCharm) does not recognize this as correct; only after (incorrectly) adding the folder name "Chessbotslack." in front of it the IDE helps out.

Any idea what to do about that?

Herman
  • 320
  • 2
  • 16