There is a QGIS plugin based on the PyQGIS/PyQt code with some imports defined in the beginning:

from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

from qgis.core import *
from qgis.utils import *
from qgspasswordlineedit import QgsPasswordLineEdit

Due to my personal desire and the Zen of Python, I would like to make my imports explicit instead of implicit. How can I implement that?

So, instead of the from qgis.core import * it should be from qgis.core import QgsProject, QgsVectorLayer, QgsDataSourceUri, QgsCoordinateReferenceSystem, Qgis.

I did the above attempt manually, maybe there is an automated way. Perhaps, I can solve it with my IDLE - PyCharm.

I am aware that this is a pure StackOverflow question, however, there might be some PyQGIS/PyQt tricks for my issue available.



1 Answer 1


Indeed as was mentioned by @J.Monticolo in a comment: removestar package is a nice option.

Tool to automatically replace import * imports in Python files with explicit imports

Requires pyflakes.

Current limitations:

  • Assumes only names in the current file are used by star imports (e.g., it won’t work to replace star imports in __init__.py).

PyQGIS must be available in the same Python environment where the removestar would be installed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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