关于macos:没有名为psycopg2和请求的模块

no module named psycopg2 and requests

我在Mac(Sierra)中运行QGIS,但由于以下错误,无法加载处理插件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
>>> 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在此链接中找到了类似的文章:

[链接到上一个日志](importError:没有模块命名请求)

当我在python窗口中键入import requestsimport psycopg2时,我没有收到任何错误:

Image

你知道为什么会这样吗?我很感激你的帮助。


因为您可以在您的机器上安装各种版本的python,所以要确保pip install psycopg2-binary requests确实适用于您的qgis python环境并不总是那么简单。

您可能更喜欢从qgis python控制台安装包,执行以下操作:

1
2
3
from pip._internal import main as pipmain

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

尝试安装这些包

1
pip install psycopg2-binary requests