Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I need to develop a couple of qgis-plugins. I made some promising first steps and completed a few easy plugins. Now its time to move to more complex plugins which need to import several tool-classes I developed.

As this is quite a lot of stuff and most of my plugins need to use these libraries I wonder wether it is possible to copy them somewhere where all plugins could import them from. This needs to be a folder which is accessable for the current user. I thought about using something like "/home/username/.qgis/python/plugins/includes" but I couldn't get this working.

Can anybody give me a tip?

Thanks and regards

Ok - hello again,

on writing it occured to me - I can use "/home/username/.qgis/python" to put my classes in - I guess that's why its called like that!

Thanks again

share|improve this question
    
not directly linked to your question, but essential : be careful of the licence, any import of your libs triggers the GPL «contamination» of QGIS GPL libs. –  Vincent Jul 11 '12 at 11:28
add comment

1 Answer

In the Python console in QGIS you can see what system paths are available to the interpreter:

>>> import sys
>>> sys.path

Any package or module located on one of those paths will be available to import. Here are some solutions to a shared module library approach:

  • Adding packages to /home/username/.qgis/python, though this requires you to manage your own install/updates to this location from within one of your plugins, if you decide to release them to the public via the plugin repository. Many users expect plugin components to be installed in /home/username/.qgis/python/plugins, so this may not be a good solution with regards to maintainability.
  • Create a library plugin that users have to also install in addition to your other plugins. Some developers have taken this approach as it allows the library plugin to be updated via the Plugin Installer, independent of the other tool plugins. The library plugin does not need to have any GUI, but could offer one if 'global' settings are to be edted by the user. Useful if you intend to build many plugins based off the library, but a bit annoying to users.
  • Don't create separate plugins for your tools. Keep all of your tools (would-be plugins) in one plugin, along with the shared module library. This is the approach used by fTools, CadTools, and other multi-tool plugins. Your tools can appear to the user as separate plugins in the GUI, or in your own toolbar or menu.

Regardless of your solution, it's important that your packages use unique names so as to not cause namespace conflicts on import. /home/username/.qgis/python/includes is a bit too generic. Also, any shared module library folder on a sys.path needs to have Python package structure to be importable (e.g. contain at least an __init__.py file)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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