01-31-2016, 01:21 PM | #1 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
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?
|
01-31-2016, 01:42 PM | #2 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
List it as a requirement and tell users to use pip install?
Or else bundle it in the plugin and use that copy... |
01-31-2016, 02:53 PM | #3 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
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 |
01-31-2016, 03:00 PM | #4 |
Wizard
Posts: 4,520
Karma: 121692313
Join Date: Oct 2009
Location: Heemskerk, NL
Device: PRS-T1, Kobo Touch, Kobo Aura
|
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.
|
01-31-2016, 03:37 PM | #5 |
Grand Sorcerer
Posts: 27,551
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
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. |
01-31-2016, 03:47 PM | #6 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
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. |
01-31-2016, 06:02 PM | #7 |
Sigil Developer
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
|
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 |
01-31-2016, 06:47 PM | #8 |
Grand Sorcerer
Posts: 27,551
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
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.
Last edited by DiapDealer; 01-31-2016 at 06:52 PM. |
01-31-2016, 06:56 PM | #9 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
|
01-31-2016, 08:36 PM | #10 | |
Grand Sorcerer
Posts: 27,551
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
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). |
|
01-31-2016, 09:02 PM | #11 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
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. |
02-01-2016, 01:55 AM | #12 | |
Grand Sorcerer
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
What kind of package are you looking for? |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mini Python on mini, dies on import library | mokayak | Kobo Developer's Corner | 5 | 04-10-2015 11:02 AM |
python error: No module named MySQLdb | stgabriel | Development | 1 | 03-10-2013 02:13 PM |
No Module name Tkinter on plugin import | foghat | Plugins | 1 | 11-11-2010 07:11 PM |
Import ebook conversion in python script | erollisi | Calibre | 1 | 08-19-2010 09:43 PM |