-
artemiziy
- Активный участник
- Сообщения: 115
- Зарегистрирован: 29 апр 2008, 11:08
- Проекты: 1/1
- Репутация: 7
QGIS. Ошибка при выполнении сценария Python
Всем добрый день,
При попытке настроить в QGIS «Анализ данных» — «Параметры…» возникает следующее сообщение:
Код: Выделить всё
Ошибка при выполнении сценария Python:
TypeError: function takes exactly 5 arguments (1 given)
Traceback (most recent call last):
File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\gui\ConfigDialog.py", line 150, in accept
self.tr('Wrong value for parameter "%s":\n\n%s' % (setting.description, unicode(e))))
TypeError: function takes exactly 5 arguments (1 given)
Версия Python: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
Версия: 2.14.1-Essen Essen, ea85bef
Расположение Python:
C:/OSGEO4~1/apps/qgis/./python/plugins\processing
C:/OSGEO4~1/apps/qgis/./python
C:/Users/nikartem/.qgis2/python
C:/Users/nikartem/.qgis2/python/plugins
C:/OSGEO4~1/apps/qgis/./python/plugins
C:\OSGEO4~1\apps\Python27\lib\site-packages\matplotlib-1.3.1-py2.7-win-amd64.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\nose-1.3.3-py2.7.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\tornado-4.0.1-py2.7-win-amd64.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\backports.ssl_match_hostname-3.4.0.2-py2.7.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\certifi-14.05.14-py2.7.egg
c:\osgeo4~1\apps\python27\lib\site-packages\python_dateutil-2.1-py2.7.egg
C:\OSGEO4~1\bin\python27.zip
C:\OSGEO4~1\apps\Python27\DLLs
C:\OSGEO4~1\apps\Python27\lib
C:\OSGEO4~1\apps\Python27\lib\plat-win
C:\OSGEO4~1\apps\Python27\lib\lib-tk
C:\OSGEO4~1\bin
C:\OSGEO4~1\apps\Python27
C:\OSGEO4~1\apps\Python27\lib\site-packages
C:\OSGEO4~1\apps\Python27\lib\site-packages\PIL
C:\OSGEO4~1\apps\Python27\lib\site-packages\jinja2-2.7.2-py2.7.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\markupsafe-0.23-py2.7-win-amd64.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\pytz-2012j-py2.7.egg
C:\OSGEO4~1\apps\Python27\lib\site-packages\win32
C:\OSGEO4~1\apps\Python27\lib\site-packages\win32\lib
C:\OSGEO4~1\apps\Python27\lib\site-packages\Pythonwin
C:\OSGEO4~1\apps\Python27\lib\site-packages\wx-2.8-msw-unicode
C:/Users/nikartem/.qgis2//python
C:\OSGEO4~1\apps\qgis\python\plugins\fTools\tools
Версия QGIS — 2.14.1-Essen, поставлена через OSGeo4W64
подскажите, пожалуйста, проблема в каких-то настройках?
-
Даниил Белый
- Новоприбывший
- Сообщения: 5
- Зарегистрирован: 19 ноя 2015, 12:38
- Репутация: 0
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
Даниил Белый » 09 фев 2018, 16:15
Такая же ошибка и у меня выпадает и при тех же обстоятельствах.
-
drrrrr
- Участник
- Сообщения: 85
- Зарегистрирован: 31 янв 2012, 10:51
- Репутация: 50
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
drrrrr » 09 фев 2018, 17:01
Разбирался я с этой злосчастной ошибкой, причина — фиг догадаешься — в настройках grass проверяется наличие пути %OSGEO4W_ROOT%\apps\msys. Создайте эту папку руками ну или установите пакет msys.
-
Denis Rykov
- Гуру
- Сообщения: 3376
- Зарегистрирован: 11 апр 2008, 21:09
- Статьи: 33
- Проекты: 9
- Репутация: 529
- Ваше звание: Author
-
Контактная информация:
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
Denis Rykov » 09 фев 2018, 20:52
Даниил Белый писал(а): ↑
09 фев 2018, 16:15
Такая же ошибка и у меня выпадает и при тех же обстоятельствах.
Может быть стоит обновить QGIS?
Spatial is now, more than ever, just another column- The Geometry Column.
-
Svettlana
- Новоприбывший
- Сообщения: 6
- Зарегистрирован: 09 фев 2018, 10:39
- Репутация: 0
- Откуда: Симферополь
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
Svettlana » 12 фев 2018, 10:44
Добрый день! Помоги пожалуйста.
При Preprocessing Sentinel-2 где -то при 60% выполнения постоянно выпадает (независимо от версии QGIS или используемого компьютера):
Traceback (most recent call last):
File «C:/Users/Irina/.qgis2/python/plugins\SemiAutomaticClassificationPlugin\maininterface\sentinelTab.py», line 164, in performSentinelConversion
self.sentinel2(cfg.ui.S2_label_86.text(), o)
File «C:/Users/Irina/.qgis2/python/plugins\SemiAutomaticClassificationPlugin\maininterface\sentinelTab.py», line 249, in sentinel2
cfg.mx.msgErr38(outR)
File «C:/Users/Irina/.qgis2/python/plugins\SemiAutomaticClassificationPlugin\core\messages.py», line 248, in msgErr38
self.msgBarError(cfg.QtGuiSCP.QApplication.translate(«semiautomaticclassificationplugin», «Error») + » [38]», cfg.QtGuiSCP.QApplication.translate(«semiautomaticclassificationplugin», «Unable to load raster » + path))
TypeError: function takes exactly 5 arguments (1 given)
Как решить эту проблему?
-
gamm
- Гуру
- Сообщения: 3975
- Зарегистрирован: 15 окт 2010, 08:33
- Репутация: 1035
- Ваше звание: программист
- Откуда: Казань
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
gamm » 12 фев 2018, 11:07
запустить в отладчике, или поставить отладочную печать в том месте, где не хватает параметров. Обычно ерунда какая-нибудь, типа русских букв в путях, или отсутствия какой-нибудь папки (которых у Сентиля хватает). Или пальчиком по коду поводить в этом месте, посмотреть, какие такие 5 аргументов в функцию должны попасть.
-
Даниил Белый
- Новоприбывший
- Сообщения: 5
- Зарегистрирован: 19 ноя 2015, 12:38
- Репутация: 0
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
Даниил Белый » 13 фев 2018, 18:20
drrrrr:
Разбирался я с этой злосчастной ошибкой, причина — фиг догадаешься — в настройках grass проверяется наличие пути %OSGEO4W_ROOT%\apps\msys. Создайте эту папку руками ну или установите пакет msys.
Это помогло! Выражаю огромную благодарность!!!
-
Svettlana
- Новоприбывший
- Сообщения: 6
- Зарегистрирован: 09 фев 2018, 10:39
- Репутация: 0
- Откуда: Симферополь
Re: QGIS. Ошибка при выполнении сценария Python
Сообщение
Svettlana » 13 фев 2018, 19:46
gamm писал(а): ↑
12 фев 2018, 11:07
Обычно ерунда какая-нибудь, типа русских букв в путях
Все получилось! Огромное спасибо!
I’ve been using QGIS for a while and haven’t had any major issues so far, but now I am getting the following Python error messages and certain plugins won’t work. Any Ideas?
Failed to open Python console:
Traceback (most recent call last):
File "", line 2, in
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/console/console.py", line 46, in show_console
_console = PythonConsole(parent)
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/console/console.py", line 83, in __init__
self.console = PythonConsoleWidget(self)
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/console/console.py", line 109, in __init__
self.shell = ShellScintilla(self)
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/console/console_sci.py", line 86, in __init__
self.refreshSettingsShell()
File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/console/console_sci.py", line 141, in refreshSettingsShell
self.setCaretForegroundColor(cursorColor)
TypeError: setCaretForegroundColor(self, QColor): argument 1 has unexpected type 'unicode'
Python version:
2.7.10 (default, Jul 30 2016, 18:31:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
QGIS version:
2.18.0 'Las Palmas', exported
Python path:
['/Users/Harry/.qgis2/python/plugins/processing', '/Applications/QGIS.app/Contents/MacOS/../Resources/python', u'/Users/Harry/.qgis2/python', u'/Users/Harry/.qgis2/python/plugins', '/Applications/QGIS.app/Contents/MacOS/../Resources/python/plugins', '/Library/Frameworks/SQLite3.framework/Versions/C/Python/2.7', '/Library/Frameworks/GEOS.framework/Versions/3/Python/2.7/site-packages', '/Library/Python/2.7/site-packages/scipy-override', '/Library/Python/2.7/site-packages/numpy-override', '/Library/Python/2.7/site-packages/matplotlib-override', '/Library/Frameworks/GDAL.framework/Versions/2.1/Python/2.7/site-packages', '/Library/Python/2.7/site-packages/PySAL-1.12.0-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', u'/Users/Harry/.qgis2//python', '/Users/Harry/.qgis2/python/plugins/gearthview/ext-libs', u'/Users/Harry/Documents/Work/RCA/10.yr_2/ADS_3/mapping/qgs']
I also get this error when trying to run Cartographic Line Generalization plugin:
2016-12-07T15:01:02 1
Traceback (most recent call last):
File "/Users/Harry/.qgis2/python/plugins/CartoLineGen-master/cartolinegen.py", line 210, in run
self.count_vertices()
File "/Users/Harry/.qgis2/python/plugins/CartoLineGen-master/cartolinegen.py", line 234, in count_vertices
feat = inLayer.getFeatures()
AttributeError: 'QgsRasterLayer' object has no attribute 'getFeatures'
Skip to content
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Labels
Bug
Either a bug report, or a bug fix. Let’s hope for the latter!
Feedback
Waiting on the submitter for answers
I use Windows 10 OS and not good at coding. I have been using QGIS standalone installer for a long time (from 1.8 actually), but recently tried installing the OSGEO4W 32 bit version which had the latest QGIS 2.16 version, but when I load the application I get this error and none of the plugins show up, even the ftools (vector analysis). I have attached the error message below.
I did search for solutions, where I found some discussions talking about «python-future» but I don’t know what to do exactly with that downloaded folder.
I tried pasting that folder content inside this path «C:\OSGeo4W\apps\Python27\Lib\site-packages\future» and restarted the application and it still didn’t fix anything.
Can anyone provide a solution? Error message is provided below.
"**Couldn't load QGIS utils.
Python support will be disabled.**
Traceback (most recent call last):
File "", line 1, in
File "C:/OSGeo4W/apps/qgis/./python\qgis\utils.py", line 21, in
standard_library.install_aliases()
File "C:\OSGeo4W\apps\Python27\lib\site-packages\future\standard_library\__init__.py", line 457, in install_aliases
__import__(oldmodname)
File "C:\OSGeo4W\apps\Python27\lib\site-packages\future\backports\__init__.py", line 17, in
from .misc import (ceil,
File "C:\OSGeo4W\apps\Python27\lib\site-packages\future\backports\misc.py", line 24, in
from socket import getaddrinfo, SOCK_STREAM, error, socket
File "C:\OSGeo4W\apps\Python27\lib\socket.py", line 68, in
from _ssl import \
ImportError: cannot import name RAND_egd
Python version:
2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]
QGIS version:
2.16.0-Nødebo 'Nødebo', d0b3e39
Python path:
['C:/OSGeo4W/apps/qgis/./python', u'C:/Users/Satish/.qgis2/python', u'C:/Users/Satish/.qgis2/python/plugins', 'C:/OSGeo4W/apps/qgis/./python/plugins', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\matplotlib-1.3.1-py2.7-win32.egg', 'c:\\osgeo4w\\apps\\python27\\lib\\site-packages\\python_dateutil-2.2-py2.7.egg', 'C:\\OSGeo4W\\bin\\python27.zip', 'C:\\OSGeo4W\\apps\\Python27\\DLLs', 'C:\\OSGeo4W\\apps\\Python27\\lib', 'C:\\OSGeo4W\\apps\\Python27\\lib\\plat-win', 'C:\\OSGeo4W\\apps\\Python27\\lib\\lib-tk', 'C:\\OSGeo4W\\bin', 'C:\\OSGeo4W\\apps\\Python27', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\PIL', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\jinja2-2.7.2-py2.7.egg', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\markupsafe-0.23-py2.7-win32.egg', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\pytz-2014.2-py2.7.egg', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\win32', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\Shapely-1.2.18-py2.7-win32.egg', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\six-1.10.0-py2.7.egg', 'C:\\OSGeo4W\\apps\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']"
Fellow researchers and open-source GIS enthusiasts,
Welcome to my blog!
I’d like to start with a disclaimer – I may be a researcher of this very area but that doesn’t mean everything I do or write here will work for you, in your own desktop configurations and package versions. I have no responsibility if you lose data or mess up your installation. I also do not authorize any copies of my content.
Today, I am writing about an error I obtained while using QGIS 3.20 Python Console. I was trying to clip a vector layer populated with points I had just created, by an extent of the type $xmin,xmax,ymin,ymax$, using the tool Clip Vector by Extent, from GDAL.
The error
First, I ran the following line, to set the tool parameters:
paramgdal= {'INPUT': points_layer, 'EXTENT':extent_final, 'OUTPUT':output_path}
The variables “extent_final” and “output_path” were previously set. “points_layer” is the vector layer of the type shapefile in which the points I want to clip by the extent are stored. It was loaded previously, using the following snippet:
points_layer = QgsVectorLayer(path_to_file, 'points_loaded', 'ogr')
Well, so far, so good.
But, after setting the parameters, I ran:
processing.run("gdal:clipvectorbyextent", paramgdal)
and then, this error appeared:
ERROR 1: Attempt to write non-multipoint (POINT) geometry to multipoint shapefile.
ERROR 1: Unable to write feature 0 from layer points_layer.
ERROR 1: Terminating translation prematurely after failed translation of layer points_layer (use -skipfailures to skip errors)
And the resulting layer was not correctly generated.
Interpretation of the issue
Re-reading the error message, I noticed that GDAL, for some reason, tries to save the generated layer as a Multipoint shapefile, instead of, simply, a Point shapefile. For this reason, it is unable to write any of the features from the original layer on the new one, because their types do not match.
Solution
Checking on the QGIS documentation we can notice that there are four possible parameters to run gdal:clipvectorbyextent. One of them, “OPTIONS”, is Optional, and refers to GDAL creation options. Because the algorithm Clip Vector by Extent is based on the GDAL utility ogr2ogr, the options available for the original algorithm can be used to build the new layer through the Python Console as well.
Especially, one of the options is useful in this scenario. The “nlt” option of ogr2ogr defines the geometry of the generated file, which is just what we were looking for. In the case here shown, I simply added
'OPTIONS': '-nlt point'
to the $gdalparams$ Python dictionary. This tells GDAL that the layer to be created is a point layer, and it solved my issue completely. The code snippet shown at the start of this post was adapted by me as:
paramgdal= {'INPUT': points_layer, 'EXTENT':extent_final, 'OPTIONS': '-nlt point', 'OUTPUT':output_path}
processing.run("gdal:clipvectorbyextent", paramgdal)
And when I ran the snippet above, the clipped point layer was correctly generated, without any errors or warnings.
A simple fix!
- Why don’t you simply use GDAL from the command line, or click on the tool through the Processing Toolbox and use it directly from the GUI? Why do you want to use the Python Console on QGIS?
Because sometimes the Python Console is the most practical way to perform a calculation, and this code snippet shown here is a small part of a large code. For this motive, it is not worth it to change the whole interface or language in which we are developing code.
- I loaded my vector file using the QGIS Python Console, but it did not appear on the layers list on QGIS! What happened?
This is not an issue. The code snippet used to load the vector layer does not list the layer on QGIS Layers panel, nor shows it in the map visualization. To do that, you should run
QgsProject.instance().addMapLayers([points_layer])
- I’m not sure what I should import before using the tool “gdal:clipvectorbyextent” on QGIS Python Console.
You should import the QGIS algorithms and the processing tool. See the snippet below:
from qgis.core import *
import processing