【发布时间】:2015-10-24 23:39:22
【问题描述】:
我是 python 新手,我正在尝试使用 fabric 和 matplotlib 模块。 我已经用 conda 创建了一个虚拟环境,并且正在编写程序并在虚拟环境中执行。
我编写了一个使用fabric.api(一个fabfile.py)的脚本。我正在将此 fabfile 导入另一个 python 脚本(Window.py)并使用 Window.py 中 fabfile 中的定义。一切正常,我很高兴。
现在我想在我使用 Fabric 提取的一些数据上绘制图表。所以我做了一个研究,发现 matplotlib 适合我的目的。我在虚拟环境中从 conda 安装了这个模块。所以令我惊讶的是,一旦我安装了它并运行了我的 Window.py,我得到了下面显示的错误!
**Traceback (most recent call last):
File "Window.py", line 9, in <module>
from fabfile import *
File "F:\home\WorkSpace\FIrstPyProject\TestModules\fabfile.py", line 2, in <module>
from fabric.api import *
ImportError: No module named fabric.api**
这是我的代码示例,
Fabfile.py
from fabric.api import *
import sys
def hello():
print "hello world"
def connect(commandInput):
print "starting to connect"
env.host_string = 'nms@10.0.0.70'
env.password = "nms"
with hide('output','running'):
p=run(commandInput)
return p
窗口.py
import Tkinter as tk
import csv
import MasterWindow
from fabfile import *
import time
from fabric.api import *
LARGE_FONT= ("Verdana", 12)
env.host_string = 'nms@10.0.0.70'
env.password = "nms"
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Graphy-Home", font=LARGE_FONT)
label.pack(pady=10,padx=10)
Command = tk.Label(self, text="Enter Command")
pickCommand = tk.Entry(self)
pickCommand.pack(pady=10)
Command.pack()
button1 = tk.Button(self, text="Submit Command", command=lambda: submit())
button1.pack()
def submit(ItrCnt=0,sleepTime=3):
while (ItrCnt < 10):
print (pickCommand.get())
cmd=pickCommand.get()
ItrCnt=ItrCnt+1
time.sleep(sleepTime)
p=connect(cmd)
print(p.stdout)
当我以下面显示的方式在 fabfile 中运行 defs 时,一切都很好,
fab -a connect
但是当我从 Window.py 调用 Connect() 时,事情并没有像安装 matplotlib 之前那样工作
我在下面的链接中看到了一个与我在此处提出的问题最相似的问题
Python import error :No module named Fabric.api?
我从这里接受的答案中得到了很多帮助,因为我现在不想使用 PIP,因为 PIP 对我的窗口有一些依赖,但没有得到解决。我想使用 conda 本身。无论如何我可以解决这个问题吗?提前致谢
【问题讨论】:
标签: python linux tkinter fabric conda