没有名为 psycopg2 的模块和请求

Posted

技术标签:

【中文标题】没有名为 psycopg2 的模块和请求【英文标题】:no module named psycopg2 and requests 【发布时间】:2018-12-13 05:09:32 【问题描述】:

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

>>> 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: No module named requests)

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

任何想法为什么会发生这种情况? 非常感谢任何帮助。

【问题讨论】:

【参考方案1】:

由于您可以在您的机器上安装各种版本的 Python,因此要确保 pip install psycopg2-binary requests 真正适用于您的 QGIS Python 环境并不总是那么简单。

您可能更喜欢从 QGIS Python console 安装包,执行以下操作:

from pip._internal import main as pipmain

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

【讨论】:

【参考方案2】:

尝试安装这些软件包

pip install psycopg2-binary requests

【讨论】:

嗨@JohnKlehm,发出此命令后错误仍然存​​在。这是错误:>>> 导入 psycopg2 文件“/usr/local/Cellar/qgis2/2.18.21/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py”,第 607 行,在 _import mod = _builtin_import(name, globals, locals, fromlist, level) ImportError: No module named psycopg2

以上是关于没有名为 psycopg2 的模块和请求的主要内容,如果未能解决你的问题,请参考以下文章

ImportError:没有名为“psycopg2._psycopg”的模块

Django,mod_wsgi,psycopg2 配置不当:加载 psycopg2 模块时出错:没有名为 _psycopg 的模块

ImportError:没有名为 psycopg2 的模块

错误:没有名为 psycopg2.extensions django postgresql 的模块

django 应用程序的 Heroku 推送得到“没有名为 psycopg2.extensions 的模块”

Dokku 编译错误 - django.core.exceptions.ImproperlyConfigured: 加载psycopg2模块时出错,没有名为'psycopg2'的模块。