Ghadjeres / DeepBach

code accompanying "DeepBach: a Steerable Model for Bach Chorales Generation" paper
MIT License
500 stars 131 forks source link

python ImportError: attempted relative import with no known parent package #50

Closed bbbmusic closed 6 years ago

bbbmusic commented 6 years ago

Hello Gaetan,

for installation on a mac, I followed the instructions of http://hansekbrand.se/code/DeepBachOSX.html and this seemed to work. Except I had to install tensorflow1.8 because it didn't find the recommended version 1.5. Also I had to install not the latest version of python, which is now 3.7 but 3.6. After that, all the dependencies were installed without any error. Fine, so far.

But when I run: python3 -m flask run --host=0.0.0.0

I got the following python related error, which is well discussed in the web, but I'm unable solve it: "ImportError: attempted relative import with no known parent package". I copied the whole terminal message, but the interesting part is the second half :

 * Serving Flask app "/Users/myUserName/src/DeepBach-master/plugin_flask_server.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
Using TensorFlow backend.
Usage: python -m flask run [OPTIONS]

Error: While importing "plugin_flask_server", an ImportError was raised:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/cli.py", line 235, in locate_app
    __import__(module_name)
  File "/Users/myUserName/src/DeepBach-master/plugin_flask_server.py", line 182, in <module>
    open(pickled_dataset, 'rb'))
  File "/Users/myUserName/src/DeepBach-master/DeepBach/metadata.py", line 5, in <module>
    from .data_utils import SUBDIVISION
ImportError: attempted relative import with no known parent package

and here is what i did, one after another:

export PYTHONPATH=/Users/myUserName/src/DeepBach-master/DeepBach

python3

import music21
us=music21.environment.UserSettings()
us['musicxmlPath']='/Applications/MuseScore 2.app'
exit()

# Start Musescore 2 manually, by hand !!!

# server
cd /Users/myUserName/src/DeepBach-master/DeepBach
export FLASK_APP=/Users/myUserName/src/DeepBach-master/plugin_flask_server.py

python3 -m flask run --host=0.0.0.0

the last message triggers the error.

Here is the structure of my deepbach installation: mydeepbachstructure

bbbmusic commented 6 years ago

I solved this issue by replacing all relative paths to absolute paths, like python3 deepBach.py -l 100 to python3 absoulute/path/to/deepBach.py -l 100 There are now some other issues and errors, but it's a hopeful starting point.

Ghadjeres commented 6 years ago

Thanks! And sorry for the late answer.