在cx_freeze中创建可执行文件时要安装的从属模块

时间:2016-03-18 08:36:40

标签: python-2.7 packaging cx-freeze

我创建了一个依赖于库speedtest-cli的python脚本。现在我将它打包成可执行文件。但是,我不想使用我的脚本安装speedtest-cli为所有用户创建开销。如何在setup.py文件中指定,以便在安装我的exe时自动安装speedtest-cli。

我正在使它成为一个独立的应用程序。

from cx_Freeze import setup,Executable
import sys


includes = ["speedtest-cli"]

setup(name = "Bandwithtest",
      version = "1.0",
      options = {"build_exe" : {"includes" : includes}},
      executables = [Executable("networktest.py")]

添加模块包括不起作用。它引发导入错误。 ImportError:没有名为' speedtest-cli'

的模块

我有两个问题

  1. 如何确保用户安装应用程序时安装speedtest-cli?

  2. 我已经在我的模块中导入了speedtest-cli,虽然我在我的程序中没有使用它。理想情况下,cx_freeze会自动捆绑所有导入的模块。但它对speedtest-cli没有这样做。为什么会这样呢?

  3. 这是我试图冻结的脚本。

    class Net(threading.Thread):
    
       def __init__(self, interval):
          threading.Thread.__init__(self)
          self.interval = interval
    
       def run(self):
    
          self.main()
    
       def main(self,interval):
    
          try:
            while thread1.is_alive():
               p = subprocess.Popen(r'speedtest-cli',
                                  stdout = PIPE, 
                                  stderr = PIPE)  #--> This is definitely required
    
       except KeyboardInterrupt as e:
             print "Exiting", e
    
    
    
    class UI:
    
      def __init__(self,* args, **kwargs):        
    
         tk.Tk.__init__(self, *args, **kwargs)
    
         self.wm_title("Network Test")
         self.geometry('250x75')
         self.resizable(width = False, height = False)
    
         self.label = tk.Label(text = "Frequency(seconds)")
         self.label.grid(row = 0, column = 0)
    
         self.entry = tk.Entry(bd = 5)
         self.entry.grid(row = 0, column = 1)
    
         self.button = tk.Button(text = "Start Test", command = self.callthread)
    
         self.button.grid(row = 1, column = 0)
    
         self.button1 = tk.Button(text = "Stop Test")
         self.button1.grid(row = 1, column = 1)
    
         self.mainloop()
    
    def callthread(self):
    
       thread2 = Net(self.entry.get())
       thread2.start()
    
    
    if __name__ == "__main__":
    
       thread1 = threading.Thread(target = MyUI)
       thread1.start()
    

    先谢谢。

0 个答案:

没有答案