Skip to main content
deleted 91 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I've developed a QGIS plugin that needs to have installed external libraries to work. While I was working I've installed those libraries with pip command via osgeo4W shell but I don't want to each one on my company that want tot use the plugin have to go to the osgeo4W shell to install it. I'm not able to make my code running correctly to automatically install libraries when install the plugin. I've tried with multiple ways, last one is that but seems to do nothing... and by now I'm a little bit lost on my purpose.

main plugin file:

if os.path.isfile('install_deps.py'):
        print('WARNING: new dependies will be installed....')
        import install_deps
        install_deps.installer_func
        os.rename('install_deps.py', 'install_deps.installed')
    else:
        pass

install_deps.py file

import os

def installer_func():
    plugin_dir = pathlib.Path(__file__).parent.parent

    try:
        import pip
    except ImportError:
        exec(
            open(str(pathlib.Path(plugin_dir, 'scripts', 'get_pip.py'))).read()
        )
        import pip
        # just in case the included version is old
        pip.main(['install', '--upgrade', 'pip'])

    sys.path.append(plugin_dir)

    with open(str(plugin_dir / 'requirements.txt'), "r") as requirements:
        for dep in requirements.readlines():
            dep = dep.strip().split("==")[0]
            try:
                __import__(dep)
            except ImportError as e:
                print("{} not available, installing".format(dep))
                pip.main(['install', dep])

requirements.txt file:

fuzzywuzzy==0.19.0
Unidecode==1.3.2

Can anyoneyou help me please? There is some big mistake in the approach? Thank you in advance for your time ;)

I've developed a QGIS plugin that needs to have installed external libraries to work. While I was working I've installed those libraries with pip command via osgeo4W shell but I don't want to each one on my company that want tot use the plugin have to go to the osgeo4W shell to install it. I'm not able to make my code running correctly to automatically install libraries when install the plugin. I've tried with multiple ways, last one is that but seems to do nothing... and by now I'm a little bit lost on my purpose.

main plugin file:

if os.path.isfile('install_deps.py'):
        print('WARNING: new dependies will be installed....')
        import install_deps
        install_deps.installer_func
        os.rename('install_deps.py', 'install_deps.installed')
    else:
        pass

install_deps.py file

import os

def installer_func():
    plugin_dir = pathlib.Path(__file__).parent.parent

    try:
        import pip
    except ImportError:
        exec(
            open(str(pathlib.Path(plugin_dir, 'scripts', 'get_pip.py'))).read()
        )
        import pip
        # just in case the included version is old
        pip.main(['install', '--upgrade', 'pip'])

    sys.path.append(plugin_dir)

    with open(str(plugin_dir / 'requirements.txt'), "r") as requirements:
        for dep in requirements.readlines():
            dep = dep.strip().split("==")[0]
            try:
                __import__(dep)
            except ImportError as e:
                print("{} not available, installing".format(dep))
                pip.main(['install', dep])

requirements.txt file:

fuzzywuzzy==0.19.0
Unidecode==1.3.2

Can anyone help me please? There is some big mistake in the approach? Thank you in advance for your time ;)

I've developed a QGIS plugin that needs to have installed external libraries to work. While I was working I've installed those libraries with pip command via osgeo4W shell but I don't want to each one on my company that want tot use the plugin have to go to the osgeo4W shell to install it. I'm not able to make my code running correctly to automatically install libraries when install the plugin. I've tried with multiple ways, last one is that but seems to do nothing... and by now I'm a little bit lost on my purpose.

main plugin file:

if os.path.isfile('install_deps.py'):
        print('WARNING: new dependies will be installed....')
        import install_deps
        install_deps.installer_func
        os.rename('install_deps.py', 'install_deps.installed')
    else:
        pass

install_deps.py file

import os

def installer_func():
    plugin_dir = pathlib.Path(__file__).parent.parent

    try:
        import pip
    except ImportError:
        exec(
            open(str(pathlib.Path(plugin_dir, 'scripts', 'get_pip.py'))).read()
        )
        import pip
        # just in case the included version is old
        pip.main(['install', '--upgrade', 'pip'])

    sys.path.append(plugin_dir)

    with open(str(plugin_dir / 'requirements.txt'), "r") as requirements:
        for dep in requirements.readlines():
            dep = dep.strip().split("==")[0]
            try:
                __import__(dep)
            except ImportError as e:
                print("{} not available, installing".format(dep))
                pip.main(['install', dep])

requirements.txt file:

fuzzywuzzy==0.19.0
Unidecode==1.3.2

Can you help me?

Source Link
Laura
  • 47
  • 3

Automatically install third party Python library to QGIS while first install of custom plugin (Windows)

I've developed a QGIS plugin that needs to have installed external libraries to work. While I was working I've installed those libraries with pip command via osgeo4W shell but I don't want to each one on my company that want tot use the plugin have to go to the osgeo4W shell to install it. I'm not able to make my code running correctly to automatically install libraries when install the plugin. I've tried with multiple ways, last one is that but seems to do nothing... and by now I'm a little bit lost on my purpose.

main plugin file:

if os.path.isfile('install_deps.py'):
        print('WARNING: new dependies will be installed....')
        import install_deps
        install_deps.installer_func
        os.rename('install_deps.py', 'install_deps.installed')
    else:
        pass

install_deps.py file

import os

def installer_func():
    plugin_dir = pathlib.Path(__file__).parent.parent

    try:
        import pip
    except ImportError:
        exec(
            open(str(pathlib.Path(plugin_dir, 'scripts', 'get_pip.py'))).read()
        )
        import pip
        # just in case the included version is old
        pip.main(['install', '--upgrade', 'pip'])

    sys.path.append(plugin_dir)

    with open(str(plugin_dir / 'requirements.txt'), "r") as requirements:
        for dep in requirements.readlines():
            dep = dep.strip().split("==")[0]
            try:
                __import__(dep)
            except ImportError as e:
                print("{} not available, installing".format(dep))
                pip.main(['install', dep])

requirements.txt file:

fuzzywuzzy==0.19.0
Unidecode==1.3.2

Can anyone help me please? There is some big mistake in the approach? Thank you in advance for your time ;)