【问题标题】:python3 fabric import Error: cannot import Connectionpython3结构导入错误:无法导入连接
【发布时间】:2018-08-07 21:00:52
【问题描述】:
import os
import string
from fabric import Connection
import configparser
import socket


config = configparser.RawConfigParser(allow_no_value=True)
configFilePath = r'/root/config.ini'
config.read(configFilePath)
puser = config.get('Server', 'user')
#print (puser)
db_server = list(config.items('Database'))
#print (db_server)


def host_connect():
    for key in db_server:
        print (key[0])
        conn = Connection(host="puser@{0}".format(key[0]))
        conn.run('ps -ef | grep postgres')

我正在尝试运行此代码并收到错误消息 回溯(最近一次通话最后): 文件“psql_cleanlogs.py”,第 6 行,在 从面料进口连接 ImportError:无法导入名称“连接”

我在不同的代码中完成了相同的过程,它运行良好,但它正在制造麻烦。我正在使用 python3 虚拟环境

【问题讨论】:

    标签: python-3.x


    【解决方案1】:

    我遇到了类似的问题,我检查了下载的fabric 包内容,它没有Connection.py(可能是我下载包的位置错误)。我从正确的存储库 (https://pypi.python.org/simple) 安装了 fabric2,它工作正常。

    from fabric2 import Connection
    

    【讨论】:

      猜你喜欢
      • 2019-10-08
      • 2015-12-21
      • 1970-01-01
      • 2021-05-31
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      • 1970-01-01
      相关资源
      最近更新 更多