MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Import module not in bundled Python (https://www.mobileread.com/forums/showthread.php?t=270405)

Toxaris 01-31-2016 02:21 PM

Import module not in bundled Python
 
I want to use a module in Python and it is not in the bundled Python. I can of course use a non-bundled version, but I would like to make it easier for the users. Is there a way to use a module that is not in the bundled Python?

eschwartz 01-31-2016 02:42 PM

List it as a requirement and tell users to use pip install?

Or else bundle it in the plugin and use that copy...

KevinH 01-31-2016 03:53 PM

If the module would be useful for processing epubs in general, let us know and we may consider including it in the bundled version. If not generally of use to multiple users, the best solution is to include it in the plugin if the license permits it.

Kevin

Toxaris 01-31-2016 04:00 PM

It appears (after some testing with a standalone python), that it will not work on Windows machines, only Linux and OSX. So, I will look at something else.

DiapDealer 01-31-2016 04:37 PM

Quote:

Originally Posted by eschwartz (Post 3250205)
List it as a requirement and tell users to use pip install?

That will work on Linux, but not with Windows/Mac users using Sigil's bundled Python. They could, of course, install Python themselves and then configure Sigil to use that external Python. Then your suggestion would work.

We've thought of putting a folder in Sigil's prefs (which would be included in sys.path) where pure Python modules could be dropped and thus made available to the bundled Python interpreter, but I'm not sure rooting around in Appdata would be any easier for casual folk than installing/switching to an external Python and using pip. *shrug* Still might do it, just to have options available.

eschwartz 01-31-2016 04:47 PM

That sounds like a reasonable approach, assuming plugin authors then have sample snippets like this here: https://stackoverflow.com/questions/...le-within-code
Or perhaps make it available in the launcher, if this is a significant use case.


No need to bother the hapless user. :D

KevinH 01-31-2016 07:02 PM

Given how MacOSX python is bundled, a user should be able to do a pip3 install --user and once that is done the bundled python3.4 should see it. But that is conjecture. I have not tested it to see if it actually works or not. I will.

KevinH

DiapDealer 01-31-2016 07:47 PM

Pretty sure the location where pip installs modules on Windows is hardcoded into the pip executable at install time. One used to be able open it in a hex editor and change it to a path relative to the binary (so pip could work in Python virtualenvs), but I'm not sure that still works.

eschwartz 01-31-2016 07:56 PM

Quote:

Originally Posted by DiapDealer (Post 3250354)
Pretty sure pip on Windows is still hardcoded to Python's default installation directory.

Do you mean to say on Windows pip install doesn't have the "--root", "--prefix", "--target", or "--user" switches? :blink:

DiapDealer 01-31-2016 09:36 PM

Quote:

Originally Posted by eschwartz (Post 3250364)
Do you mean to say on Windows pip install doesn't have the "--root", "--prefix", "--target", or "--user" switches? :blink:

All but "--prefix" (which I don't see listed on Windows or Linux using pip install -help)

But regardless ... I was mistaken. It's not the installation directory that's hard-coded, it's the path to the python executable that is. Almost all exes in the Pythonxx\Scripts directory (including pip) are the same way (at least up to, and including, 3.4).

eschwartz 01-31-2016 10:02 PM

I certainly see "--prefix" listed by pip3 install --help

Anywho, as per the SO link, surely this shouldn't care about hardcoded locations in the executable entry points?:

Code:

import pip

pip.main(['install', mymodule, 'further', 'optional', 'parameters'])


This should theoretically make it easy for plugin authors to install modules as needed, if they aren't available.

Doitsu 02-01-2016 02:55 AM

Quote:

Originally Posted by Toxaris (Post 3250244)
It appears (after some testing with a standalone python), that it will not work on Windows machines, only Linux and OSX. So, I will look at something else.

BTW, you can also embed some of the simpler modules by simply copying the package folder or the Python file(s) to the plugin directory.

What kind of package are you looking for?


All times are GMT -4. The time now is 08:31 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.