1

My folder structure:

ttsTacotron.py
Tacotron-2
|..
|tacotron|
 |train.py
 |synthetizer.py
 |...
|synthesize.py # imports hparams.py
|hparams.py
...

When I call synthesize.py directly it works fine, all of its imports get processed successfully. When I import synthesize in the ttsTacotron.py and call it, it fails on importing synthesize's modules. Specifically, it fails on importing hparams.

ttsTacotron.py:

import fire
import sys
import os
import importlib 
foobar = importlib.import_module("Tacotron-2.synthesize")

Tacotron folder in question is this repository but the issue is unlikely to be specific to it.

Remarks: I use importlib to handle having - in the subfolder. Can't really rename it for various reasons.

My goal: Be able to call synthetize's methods & be able to import tacotron modules from a script that is in the root folder.

asked Jun 3, 2019 at 0:40

1 Answer 1

1

This is because, when running ttsTacotron.py, Python looks up all non-relative imported modules in the directory containing ttsTacotron.py (and in the system module directories, which isn't relevant here), yet hparams.py is in the Tacotron-2 directory. The simplest fix is probably to add Tacotron-2 to the list of directories in which modules are looked up; this also eliminates the need to use importlib.

import sys
sys.path.insert(1, 'Tacotron-2')
import synthesize as foobar
answered Jun 3, 2019 at 0:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.