I'm pretty new in the python world, and I'm working with the python console inside QGIS (Master version on a Debian machine).
I have written some scripts, all of them are in the same directory (e.g. $HOME/works/scripts). So I have the following:
# -*- coding: utf-8 -*-from PyQt4.QtCore import *from PyQt4.QtGui import *from qgis.core import *from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplicationfrom PyQt4.QtGui import QAction, QIcon, QMenuimport sys, os# add pathsys.path.append('$HOME/works/scripts')# Import the code for the dialogimport my_script_dialog as cDialog# Input parametersdlg = cDialog.MyScriptDialog(iface)# show the dialogdlg.show()# Run the dialog event loopdlg.exec_()So I should be able to run it inside the python console of QGIS and the dialog should opens.
But this is the error I get when I run it:
execfile(u'/home/ma7730/works/scripts/run_my_script.py'.encode('UTF-8'))Traceback (most recent call last): File "", line 1, in File "/home/ma7730/works/scripts/run_my_script.py", line 15, in import my_script_dialog as cDialog File "/home/ma7730/works/QGIS-master/build_master_2/output/python/qgis/utils.py", line 478, in _import mod = _builtin_import(name, globals, locals, fromlist, level)ImportError: No module named my_script_dialogSo it seems that it cannot import the module my_script_dialog even if it is placed in the same folder.
Weird (at least for me, but I'm just a beginner) that I can perform the import operation outside the python console of QGIS, so using another IDE (ipython for example).
What am I missing?
أكثر...
I have written some scripts, all of them are in the same directory (e.g. $HOME/works/scripts). So I have the following:
- my_script.py (the algorithm itself. It works if run alone in the python console)
- my_script_dialog_base.ui (the UI built with Qt designer)
- my_script_dialog.py (the actions of the UI buttons)
- run_my_script.py (the file that run the script)
# -*- coding: utf-8 -*-from PyQt4.QtCore import *from PyQt4.QtGui import *from qgis.core import *from PyQt4.QtCore import QSettings, QTranslator, qVersion, QCoreApplicationfrom PyQt4.QtGui import QAction, QIcon, QMenuimport sys, os# add pathsys.path.append('$HOME/works/scripts')# Import the code for the dialogimport my_script_dialog as cDialog# Input parametersdlg = cDialog.MyScriptDialog(iface)# show the dialogdlg.show()# Run the dialog event loopdlg.exec_()So I should be able to run it inside the python console of QGIS and the dialog should opens.
But this is the error I get when I run it:
execfile(u'/home/ma7730/works/scripts/run_my_script.py'.encode('UTF-8'))Traceback (most recent call last): File "", line 1, in File "/home/ma7730/works/scripts/run_my_script.py", line 15, in import my_script_dialog as cDialog File "/home/ma7730/works/QGIS-master/build_master_2/output/python/qgis/utils.py", line 478, in _import mod = _builtin_import(name, globals, locals, fromlist, level)ImportError: No module named my_script_dialogSo it seems that it cannot import the module my_script_dialog even if it is placed in the same folder.
Weird (at least for me, but I'm just a beginner) that I can perform the import operation outside the python console of QGIS, so using another IDE (ipython for example).
What am I missing?
أكثر...