2016-08-12 87 views
2

我想用PyInstaller 2.0製作一個Python腳本的二進制版本。我正在使用基本的「hello world」tkinter腳本,但導入了一些我需要用於測試Pyinstaller的項目的依賴關係。我在運行Yosemite 10.10.5的Mac上運行。 這是我的腳本:Mac上的PyInstaller無法找到libpython2.7

#!/usr/bin/env python 
from Tkinter import * 
import Tix 
import tkMessageBox 
from sklearn import linear_model, decomposition, preprocessing 
from sklearn.preprocessing import Imputer 
from sklearn.cross_validation import cross_val_score, cross_val_predict 
from sklearn.neighbors import KDTree 
import numpy as np 
import collections 
import array 
import math 
import csv 
from collections import OrderedDict 
import matplotlib 
matplotlib.use("TkAgg") 
import matplotlib.pyplot as plt 
import matplotlib.dates as dates 
from matplotlib.mlab import PCA 
from mpl_toolkits.mplot3d import Axes3D 
from scipy.stats import mode 
import heapq 
import sqlite3 
from sqlite3 import datetime 


root = Tk() 

w = Label(root, text="Hello, world!") 
w.pack() 

root.mainloop() 

這完美運行。然而,當我去建立使用

$pyinstaller -w -F app.py 

然後我得到這個錯誤的二進制文件:

57665 ERROR: Can not find path ./libpython2.7.dylib (needed by //anaconda/bin/python) 
Traceback (most recent call last): 
    File "//anaconda/bin/pyinstaller", line 11, in <module> 
    sys.exit(run()) 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/__main__.py", line 90, in run 
    run_build(pyi_config, spec_file, **vars(args)) 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/__main__.py", line 46, in run_build 
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 788, in main 
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 734, in build 
    exec(text, spec_namespace) 
    File "<string>", line 16, in <module> 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 212, in __init__ 
    self.__postinit__() 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/building/datastruct.py", line 178, in __postinit__ 
    self.assemble() 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 543, in assemble 
    self._check_python_library(self.binaries) 
    File "//anaconda/lib/python2.7/site-packages/PyInstaller/building/build_main.py", line 626, in _check_python_library 
    raise IOError(msg) 
IOError: Python library not found: libpython2.7.dylib, Python, .Python 
This would mean your Python installation doesn't come with proper library files. 
This usually happens by missing development package, or unsuitable build parameters of Python installation. 

* On Debian/Ubuntu, you would need to install Python development packages 
    * apt-get install python3-dev 
    * apt-get install python-dev 
* If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin) 

沒有人有任何想法如何,我可以解決這一問題?當我使用沒有額外依賴關係的基本hello world示例時,也會發生此錯誤。我有//蟒蛇/的libpython2.7.dylib文件lib和我試圖連接它usr/lib目錄/使用

$sudo ln -s /usr/local/lib/libpython2.7.dylib //anaconda/lib/libpython2.7.dylib 

但是它沒有固定的問題...

回答

1

首先,我看到你正在使用conda。我跑進在Mac上完全相同的問題,具體包括:

ERROR: Can not find path ./libpython2.7.dylib 

嘗試部署的應用程序我放在一起在暢達環境。

經過大量的谷歌搜索和閱讀,我發現目前的PyInstaller不能很好地處理帶有@rpath引用的動態庫。您可以通過在Python二進制文件上運行「otool -L」來確認庫參考是否使用@rpath,對於您來說,它看起來像// anaconda/bin/python(可能是指向//anaconda/bin/python2.7的鏈接) 。

幸運的是,最近在PyInstaller的一個分支上爲conda解決了這個問題。具體的補丁是在https://github.com/conda-forge/pyinstaller-feedstock/pull/2

我做什麼使用這個分叉的版本是,我曾在我的暢達環境通過PIP下載,然後用從https://github.com/conda-forge/pyinstaller-feedstock說明使用PyInstaller的這個岔路口我暢達環境卸載PyInstaller。具體而言,這些命令:

conda config --add channels conda-forge 
conda install pyinstaller 

所以我建議切換到PyInstaller專門爲暢達環境中,此補丁版本,看看是否它可以幫助你來解決該問題就像爲我做的。

相關問題