2014-07-28

cx_Freeze 安裝到 python 3.1 以後版本遇到的問題解決辦法(無廢話)

如果你安裝 cx_Freeze 遇到類似以下訊息



In file included from source/bases/Console.c:41:0:

source/bases/Common.c: In function ‘ExecuteScript’:

source/bases/Common.c:307:5: warning: passing argument 1 of ‘PyEval_EvalCode’ from incompatible pointer type [enabled by default]


/home/user/.pyenv/versions/3.2.5/include/python3.2m/eval.h:10:24: note: expected ‘struct PyObject *’ but argument is of type ‘struct PyCodeObject *’

creating build/lib.linux-x86_64-3.2/cx_Freeze/bases

gcc -pthread build/temp.linux-x86_64-3.2/source/bases/Console.o -L/home/user/.pyenv/versions/3.2.5/lib/python3.2/config-3.2m -lpython3.2 -o build/lib.linux-x86_64-3.2/cx_Freeze/bases/Console -Xlinker -export-dynamic -lpthread -ldl -lutil -lm -s

/usr/bin/ld: cannot find -lpython3.2

collect2: ld returned 1 exit status

error: command 'gcc' failed with exit status 1

----------------------------------------



其實它問題是出在 setup.py 裡的一個判斷式, 請將紅色部分改成藍色部分即可


        if sys.platform != "win32":
            vars = distutils.sysconfig.get_config_vars()
            if not vars.get("Py_ENABLE_SHARED", 0):
                libraryDirs.append(vars["LIBPL"])
#                libraries.append("python%s.%s" % sys.version_info[:2])
                libraries.append("python%s.%sm" % sys.version_info[:2])
                if vars["LINKFORSHARED"] and sys.platform != "darwin":
                    extraArgs.extend(vars["LINKFORSHARED"].split())
                if vars["LIBS"]:



改完後再重新 install , 即可正常

Adding cx-Freeze 4.3.3 to easy-install.pth file
Installing cxfreeze script to /home/user/.pyenv/versions/3.4.1/bin
Installing cxfreeze-quickstart script to /home/user/.pyenv/versions/3.4.1/bin

Installed /home/user/.pyenv/versions/3.4.1/lib/python3.4/site-packages/cx_Freeze-4.3.3-py3.4-linux-x86_64.egg
Processing dependencies for cx-Freeze==4.3.3
Finished processing dependencies for cx-Freeze==4.3.3




當然啦, python3.1以前的 library 是不帶 m 字的, 故最好的解決辦法是先判斷 python 版本, 再決定 lib 名稱.
不過, 這不是你該做的, 是 ex_freeze 官方該做的事


user@ub1204:~/.pyenv/versions$ ls
2.7.7  3.2.5  3.4.1
user@ub1204:~/.pyenv/versions$ ls 2.7.7/lib/
libpython2.7.a  pkgconfig  python2.7
user@ub1204:~/.pyenv/versions$ ls 3.4.1/lib/
libpython3.4m.a  pkgconfig  python3.4
user@ub1204:~/.pyenv/versions$ ls 3.2.5/lib/
libpython3.2m.a  pkgconfig  python3.2
user@ub1204:~/.pyenv/versions$



沒有留言:

張貼留言