Importing module into file that gets generated by setup.py

41 Views Asked by At

At the moment I try to import something into the file that gets generated by Setuptools and setup.py.
The file it generates at the moment looks like this:

# -*- coding: utf-8 -*-
import re
import sys
from scripts.trans import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

and I need to import this into the generated code to get my code work:
from casepunc.utils import WordTokenizer
So it looks like this:

# -*- coding: utf-8 -*-
import re
import sys
from scripts.trans import main
from casepunc.utils import WordTokenizer
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

This is a dependency and it have to be in the __main__ module otherwise I get an AttributeError that it can't be found.

Background is that I got an external Model saved with PyTorch / Pickler that I need to get loaded. Its a common Problem but because of SetupUtils I can't just paste the needed import into the __main__ module like suggested.

Does anybody know how I can archive this import or any other workaround?

0

There are 0 best solutions below