no module named psycopg2 and requests

2019-08-19 01:35发布

问题:

I am running QGIS in Mac(Sierra) but I cant load the processing plugin because of this error:

>>> Couldn't load plugin 'processing' 
ImportError: No module named psycopg2 
Traceback (most recent call last):
  File .     "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 308, in loadPlugin
__import__(packageName)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/__init__.py", line 29, in 
from processing.tools.general import *              # NOQA
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/tools/general.py", line 31, in 
from processing.core.Processing import Processing
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/Processing.py", line 42, in 
from processing.script.ScriptUtils import ScriptUtils
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/script/ScriptUtils.py", line 30, in 
from processing.script.ScriptAlgorithm import ScriptAlgorithm
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/script/ScriptAlgorithm.py", line 33, in 
from processing.core.GeoAlgorithm import GeoAlgorithm
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/GeoAlgorithm.py", line 41, in 
from processing.core.parameters import ParameterRaster, ParameterVector, ParameterMultipleInput, ParameterTable, Parameter
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/core/parameters.py", line 32, in 
from processing.tools.vector import resolveFieldIndex
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing/tools/vector.py", line 35, in 
import psycopg2
  File "/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 607, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ImportError: No module named psycopg2
Python version: 2.7.15 (default, Jul  2 2018, 01:42:08) [GCC 4.2.1 
Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] 
QGIS version: 2.18.21 Las Palmas, exported 

A found a similar post from this link:

[Link to previous post] (ImportError: No module named requests)

When I type the import requests and import psycopg2 on the python window, I don't receive any errors:

Any ideas why this is occurring? Ill appreciate any help.

回答1:

As you can have various versions of Python installed on your machine, it's not always simple to be sure that pip install psycopg2-binary requests really apply to your QGIS Python environment.

You may prefer to install from the QGIS Python console the packages, doing the following:

from pip._internal import main as pipmain

pipmain(['install', 'psycopg2-binary', 'requests'])


回答2:

Try installing those packages

pip install psycopg2-binary requests