I have a (mostly working) python3 program using mkepub.
Since I need to modify it for my specific purposes I started pulling it into my directory tree (I will send a Pull Request when I'm done since I think my mods could be useful to others, but this isn't the problem).
My current directory tree is:
.
├── markright
│ ├── book_parser.py
│ ├── docx_emitter.py
│ ├── emitter.py
│ ├── epub_emitter.py
│ ├── html_emitter.py
│ ├── __init__.py
│ ├── mkepub
│ │ ├── __init__.py
│ │ ├── mkepub.py
│ │ ├── templates
│ │ │ ├── container.xml
│ │ │ ├── cover.xhtml
│ │ │ ├── package.opf
│ │ │ ├── page.xhtml
│ │ │ ├── toc.ncx
│ │ │ └── toc.xhtml
│ │ └── tests
├── markright.py
I'm using mkepub
from epub_emitter.py
in this way:
from . import mkepub # <-- here I get problems
...
epub = mkepub.Book(**kwargs)
which imports ./mkepub/__init__.py
:
from .mkepub import Book # <-- here I get problems
... which finally gets to problematic code:
import jinja2
...
env = jinja2.Environment(loader=jinja2.PackageLoader('mkepub'))
This bombs at program startup (while import
ing) with the following error:
Traceback (most recent call last):
File "/home/mcon/Documents/Libro/sigil/markright/venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg/pkg_resources/__init__.py", line 359, in get_provider
KeyError: 'mkepub'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/mcon/Documents/Libro/sigil/markright/markright.py", line 1, in <module>
from markright import *
File "/home/mcon/Documents/Libro/sigil/markright/markright/__init__.py", line 4, in <module>
from .epub_emitter import EPUBemitter
File "/home/mcon/Documents/Libro/sigil/markright/markright/epub_emitter.py", line 1, in <module>
from . import mkepub
File "/home/mcon/Documents/Libro/sigil/markright/markright/mkepub/__init__.py", line 1, in <module>
from .mkepub import Book
File "/home/mcon/Documents/Libro/sigil/markright/markright/mkepub/mkepub.py", line 49, in <module>
env = jinja2.Environment(loader=jinja2.PackageLoader('mkepub'))
File "/home/mcon/Documents/Libro/sigil/markright/venv/lib/python3.7/site-packages/jinja2/loaders.py", line 224, in __init__
provider = get_provider(package_name)
File "/home/mcon/Documents/Libro/sigil/markright/venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg/pkg_resources/__init__.py", line 361, in get_provider
ModuleNotFoundError: No module named 'mkepub'
Note this works if I import
the same mkepub
(I did not modify it, yet) from system directory (or venv
).
What am I missing?
Of course I would like to change as little as possible (ideally nothing!) in mkepub
to avoid problems in future Pull Request. OTOH I can change without any problem my code.
In the process I would also like to understand better path resolution in Python3.
UPDATE: apparently the only way is to install mkepub
in a venv
and then edit files inside it (.../venv/lib/python3.7/site-packages/mkepub/...
) which looks very ugly. Is there another way?