Strange error using cx-freeze to build a PySide pr

2019-08-02 16:12发布

问题:

I am using cx-freeze4.3.3 on a 64-bit mac running python 2.7.8 installed via the anaconda python distribution. The program is very simple as follows:

import sys
from PySide.QtGui import QApplication, QDialog

app = QApplication(sys.argv)
form = QDialog()
form.show()
app.exec_()

The setup.py file is standard, with the following included:

options = {
    'build_exe': {
        'includes': 'atexit'
    }
}

executables = [
    Executable('test.py', base=base)
]

When running python setup.py build, the following error occurs:

copying libpython2.7.dylib -> build/exe.macosx-10.5-x86_64-2.7/libpython2.7.dylib error: [Errno 2] No such file or directory: 'libpython2.7.dylib'

What could be the issue here? libpython2.7.dylib is located in /anaconda/lib, which is in the system path.

回答1:

I had a similar problem with cx_freeze on OSX not finding some files to be copied. I found the solution in some forum (cannot find it again): add the following lines in function _GetDependentFiles in cx_freeze file freezer.py:

for i in range(len(dependentFiles)):
    filei = dependentFiles[i]
    if not os.path.isabs(filei):
        print 'TD bug fix: adding ' + sys.prefix + '/lib to relative path ' + filei + '!'
        dependentFiles[i] = os.path.join(sys.prefix,'lib',filei)

Now python setup.py build runs BUT the built program does not run correctly!! Probably you will have the same problem, which i could not solve. So i have posted the issue: Failed making a standalone python/Qt application with cx_freeze (or Py2App) on Mac and am hoping for an answer...