Python结构模块突然丢失

2024-09-30 10:26:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python的新手,正在尝试fabric和matplotlib模块。 我用conda创建了一个虚拟Env,并且正在编写程序并在虚拟Env中执行。在

我写了一个脚本织物.api(一)工厂文件.py). 我正在将这个fabfile导入另一个python脚本(窗口.py)使用fabfile中的定义窗口.py. 一切都很好,我很高兴。在

现在我想在我用Fabric提取的一些数据上绘制图表。所以我做了一个研究,发现matplotlib适合我的目的。我在虚拟环境中从conda安装了这个模块。所以当我安装这个并运行窗口.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**

这是我的代码示例

在工厂文件.py在

^{pr2}$

在窗口.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

但是当我从窗口.py事情不像安装matplotlib之前那样工作

我在下面的链接中看到了一个与我在这里问的问题最相似的问题

Python import error :No module named Fabric.api?

我不能从这里得到太多的帮助,因为我现在不想使用PIP,因为有一些依赖于我的windows的PIP没有得到解决。我想用康达本身。有什么问题吗?提前谢谢


Tags: textfrompyimportselfapimatplotlibcommand
1条回答
网友
1楼 · 发布于 2024-09-30 10:26:54

我将首先尝试只从模块导入所需的函数,以避免名称空间的问题。在

在您的fabfile中:

from fabric.api import env,hide,run

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

在你的Windows.py公司名称:

^{pr2}$

另外,在运行fabfile和时,请确保PYTHONPATH是相同的窗口.py,因为PYTHONPATH是Python查找要加载的模块的地方。要进行检查,请将以下行放在文件的开头:

import sys
print("PYTHONPATH:{0}".format(sys.path))

相关问题 更多 >

    热门问题