0

I'm developing a plugin for QGIS that depends on python libs that are not default installed, hence could easily be installed by the network installation.

When the plugin is a little bit more mature I will upload it to github and try to get it included into the available plugins (since I'm not a programer I'll expect it to take some time before it is included).

In the meantime, is it possible to make some kind of .bat file (or similar) that install all python libs that my plugin depend on? The users of my plugin is (hopefully) farmers that (probably) does not have a huge experience of installing complex programs so I want to make it as easy as possible for them.

  • did you think about include those libs inside your plugin folder structure (if it's not too heavy, it could not be a big deal) ? And then in your script referring by relative import class. – Hugo Roussaffa - GeoDatup Jul 22 '17 at 10:56
  • Well I could do that, hence it feels wrong to add libs like matplotlib into my folder.. Seems like it would be possible to write some .bat file that could do it? – axel_ande Jul 23 '17 at 21:37
  • Ok, and did you try to Installing python module within code ? One way is to define the matplotlib module in the setup.py and another one (if the client has pip) to install from pip module. You could also use the subprocess python's module to run whatever command you need. – Hugo Roussaffa - GeoDatup Jul 24 '17 at 7:58
-1

So inspired by the comments I found a solution, I think that this solution will work for windows users that have installed qgis with osgeo4w. Can you see any flaws in the suggested solution? (I added this code in the top of the main python file of my plugin..

import os
import sys
plugin_dir = os.path.dirname(__file__)
try:
    import pip
except:
    execfile(os.path.join(plugin_dir, get_pip.py))
    import pip
    # just in case the included version is old
    pip.main(['install','--upgrade','pip'])
    print('installed pip')

try:
    import matplotlib
except:
    import subprocess
    print('installing matplotlib')
    subprocess.call([sys.exec_prefix + '/python', "-m", 'pip', 'install', 'matplotlib'])
    import matplotlib
    print('installation completed')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.