Forum Archive

How to override site-packages?

lrr

Among my regular Pythonista scripts I have an html2text folder with an __init__.py, but import html2text never uses it because PythonistaKit.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?)

omz

You could modify sys.path before importing your own html2text, but I'd actually recommend just using a different name for your package.

lrr

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.

omz

I just tried this – I created an html2text folder with an __init__.py, and it imported just fine. What didn't work was to import html2text (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 like del 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)?

lrr

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">.