如何为Mac 64位和Python 2.7.8 64位构建cx_freeze

时间:2014-11-25 20:21:45

标签: python cx-freeze

我正在尝试使用OS 10.9在64位Mac上构建cx_Freeze并运行64位Python。 我正在运行的python是Anaconda python distribution for mac(64位)。我已将其更改为默认的python。

进入cx_freeze源目录并运行 python setup.py build 时发生以下错误:

Creating build/lib.macosx-10.5-x86_64-2.7/cx_Freeze/bases
gcc -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/source/bases/Console.o -L/Users/JJ/anaconda/lib -o build/lib.macosx-10.5-x86_64-2.7/cx_Freeze/bases/Console -s
ld: warning: option -s is obsolete and being ignored
Undefined symbols for architecture x86_64:
  "_PyDict_New", referenced from:
      _main in Console.o
  "_PyDict_SetItemString", referenced from:
      _main in Console.o
  "_PyErr_Print", referenced from:
      _main in Console.o
  "_PyEval_EvalCode", referenced from:
      _main in Console.o
  "_PyEval_GetBuiltins", referenced from:
      _main in Console.o
  "_PyImport_ImportModule", referenced from:
      _main in Console.o
  "_PyObject_CallMethod", referenced from:
      _main in Console.o
  "_PyString_FromString", referenced from:
      _main in Console.o
  "_PySys_SetArgv", referenced from:
      _main in Console.o
  "_Py_FatalError", referenced from:
      _main in Console.o
  "_Py_Finalize", referenced from:
      _main in Console.o
  "_Py_FrozenFlag", referenced from:
      _main in Console.o
  "_Py_IgnoreEnvironmentFlag", referenced from:
      _main in Console.o
  "_Py_Initialize", referenced from:
      _main in Console.o
  "_Py_IsInitialized", referenced from:
      _main in Console.o
  "_Py_NoSiteFlag", referenced from:
      _main in Console.o
  "_Py_SetProgramName", referenced from:
      _main in Console.o
  "_Py_SetPythonHome", referenced from:
      _main in Console.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1

这可能是什么问题?

1 个答案:

答案 0 :(得分:2)

其中一条评论提到gcc命令应该有一个标志' -lpython'在里面。这让我走上正轨。我能够通过添加标志' -lpython2.7'来解决问题。何时构建Console.o和ConsoleKeepPath.o。我通过在下载的cx_Freeze-4.3.3目录中的setup.py文件中添加以下行来实现此目的:

extensions[1].extra_link_args=['-lpython2.7']
extensions[2].extra_link_args=['-lpython2.7']

扩展中有3个元素,因此我使用扩展名[x] .name来查找正确的元素。完成后,我能够使用标准的python distutils构建和安装。