Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to override site-packages?
-
Among my regular Pythonista scripts I have an html2text folder with an
__init__.py
, butimport html2text
never uses it becausePythonistaKit.framework/pylib/site-packages/html2text.py
exists. How do I override it?sys.path
seems correct. Killing the app didn't help. (Is there a nicer way to restart the interpreter?) -
You could modify
sys.path
before importing your ownhtml2text
, but I'd actually recommend just using a different name for your package. -
sys.path
already includes the document folder as the first entry, but Python prioritizes modules over packages.I can't rename it because it consists of several modules that import each other.
It's not my package but the current (less broken) version of the same repository as is included with Pythonista.
-
I just tried this – I created an
html2text
folder with an__init__.py
, and it imported just fine. What didn't work was to importhtml2text
(the built-in version) first, and then trying to create my own package. In that case, the cached built-in module was used. To deal with that, you might want to use something likedel sys.modules['html2text']
to force reloading the module from disk.Btw, which version of Pythonista are you using, and if it's 3.0, which version of Python (2.7 or 3.5)?
-
Wouldn't killing the app accomplish the reloading?
I renamed the package and changed all the internal imports to html3text, and have a working script now.
It's Pythonista 2. I bought 3 but haven't gotten around to switching.
The problem is that the built-in html2text can't deal with missing CSS definitions, which affects pretty much every page on the web, unless you implement your own handling of
<link rel="stylesheet">
.