exe文件没有运行(cx_Freeze + PySide)

时间:2013-03-22 18:32:02

标签: pyside cx-freeze

使用cx_freeze冻结我的Python程序后,我尝试运行已创建的exe文件,但它没有运行。

PhoneBook.py

import  sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtUiTools import *

class PhoneBook:
  i=0;
  def __init__(self):
        loader = QUiLoader();       
        file = QFile("PhoneBook.ui");   
        file.open(QFile.ReadOnly);  
        self.ui = loader.load(file);    
        file.close();
        self.ui.setWindowIcon(QIcon('web.png'));
        self.ui.pushButton.clicked.connect(self.add);
        self.ui.pushButton_2.clicked.connect(self.load);

  def __del__ ( self ):
        self.ui = None;

  def add(self):
        loader1 = QUiLoader();      
        file1 = QFile("Add.ui");    
        file1.open(QFile.ReadOnly); 
        self.ui2 = loader1.load(file1); 
        file1.close();          
        self.ui2.show();
        self.ui2.pushButton.clicked.connect(self.get);


  def show(self):
        self.ui.show();

  def clear1(self):
        self.ui.lineEdit.clear();

  def get(self):

        name1 = self.ui2.lineEdit.text();
        name2 = self.ui2.lineEdit_2.text();

        f = open('data','a' );
        f.write(name1);
        f.write('#');
        f.write(name2);
        f.write('\n');
        f.close();
        self.load();
        self.ui2.close();

  def load(self):
        f = open('data', 'r');
        for i in range(0, 10):
            string = f.readline();
            l=len(string);
            print(string);
            print(l);
            for  c in range(0, l-1):
                if string[c]=="#":
                   break;
                print(c);       
                name1=string[0:c];
                name2=string[c+1:l-1]; 
                self.ui.tableWidget.setItem(i, 0, QTableWidgetItem(name1));
                self.ui.tableWidget.setItem(i, 1, QTableWidgetItem(name2));
                i =i+1;

  def sort(self):
        f=open('data', 'r');
        f.readlines().sort();

  if __name__ == '__main__':

        app = QApplication(sys.argv)
        app.setApplicationName('PhoneBook Application')

        w = PhoneBook();
        w.show();

        QObject.connect(app, SIGNAL('lastWindowClosed()'), app,SLOT('quit()'))

        sys.exit(app.exec_())

setup.py

import sys
from cx_Freeze import setup,Executable

includefiles = ['Add.ui', 'PhoneBook.ui', 'data', 'web.png']
includes = ["re"]
base = None
if sys.platform == "win32":
   base = "Win32GUI"
setup(name="PhoneBook", version="3.0",description="Test",options = {'build_exe':  {'include_files':includefiles, 'includes' : includes}

是因为我使用的是QUILoader吗?但是在直接执行Python代码时它会显示正确的结果。请帮帮我。

2 个答案:

答案 0 :(得分:2)

从文档来看,似乎必须包含atexit

  

cxfreeze yourapp.py --target-dir dist --base-name Win32GUI --include-modules atexit,PySide.QtNetwork --icon yourapptaskgroup.ico

该网站特别提到,如果您不包含atextit,则安装程序无法正常工作

  

“atexit”必须包含在-include-modules中,否则生成的exe将失败。

Link to the knowledge base article

答案 1 :(得分:0)

错误的另一个原因是cx-freeze正在使用来自PyQt的一些dll。

pyside和pyqt中的dll不一样,所以如果你有pyqt insalled我会建议将 PyQt4 添加到排除

 public class TreeApp<E extends Comparable<E>>
{
    private Node<E> root=null;
    private int size=0;

    private static class Node<E>
    {
        private E e;
        private Node<E> left;
        private Node<E> right;
        private Node<E> parent;

        public Node(E e,Node<E> parent,Node<E> left,Node<E> right)
        {
            this.e=e;
            this.left=left;
            this.right=right;
            this.parent=parent;
        }

        public Node(E e)
        {
            this.e=e;
        }

        public E getE() {
            return e;
        }

        public void setE(E e) {
            this.e = e;
        }

        public Node<E> getLeft() {
            return left;
        }

        public void setLeft(Node<E> left) {
            this.left = left;
        }

        public Node<E> getRight() {
            return right;
        }

        public void setRight(Node<E> right) {
            this.right = right;
        }

        public Node<E> getParent() {
            return parent;
        }

        public void setParent(Node<E> parent) {
            this.parent = parent;
        }


    }//end of Node<E> class

    public TreeApp()
    {

    }

    public Node<E> createRoot(E e,Node<E> l,Node<E> r)
    {
        if(!(root==null))
        System.out.println("Root is already present");
        root=new Node<E>(e,root,l,r);
        size++;
        return root;


    }

    public Node<E> addNode(Node<E> left,E e)
    {

        //lets start with root
        if(root==null)
            createRoot(e,null,null);
        Node<E> focusNode=root;

        //Node<E> newLeft
        Node<E> newNode=new Node<E>(e);

        //while(true)
        if(e.compareTo(focusNode.e) < 0)
        {
            if(focusNode.getLeft()==null)
            {
                focusNode.setLeft(newNode);
                size++;
            }
            else
            {
                focusNode=focusNode.getLeft();
                //addNode(focusNode,e);
            }

        }else if(e.compareTo(focusNode.e) >= 0)
        {
            if(focusNode.getRight()==null)
            {
                focusNode.setRight(newNode);
                size++;
            }
            else
            {
                focusNode=focusNode.getRight();

                //addNode(focusNode,e);
            }
        }
        return focusNode;
    }

    public void preorderTraverseTree(Node<E> focusNode) {

        if (focusNode != null) {

            System.out.println("starting traversal: " + focusNode.getE());

            preorderTraverseTree(focusNode.getLeft());
            preorderTraverseTree(focusNode.getRight());

        }

    }

    public String toString() {
        if (root == null) {
          return "";
        } else {
          return root.toString();
        }
      }

    public static void main(String args[])
    {
        //Node<String> p=new Node<String>();
        TreeApp<String> ta=new TreeApp<String>();
        System.out.println("size before: " + ta.size);

        ta.createRoot("3",null,null);
        Integer i=1;
        Integer j=2;
        System.out.println("comparison " + i.compareTo(j));
        //System.out.println("size after: " + ta.size);
        ta.addNode(ta.root,"2");
        ta.addNode(ta.root,"4");
        ta.addNode(ta.root,"1");
        ta.addNode(ta.root,"6");

        //ta.addNode(ta.root,"5");
        ta.preorderTraverseTree(ta.root);
        //System.out.println("size after: " + ta.size);



    }

}