Mac上的PyInstaller无法找到libpython2.7

时间:2016-08-12 14:09:56

标签: python exe pyinstaller

我正在尝试使用PyInstaller 2.0制作Python脚本的二进制版本。我正在使用一个基本的"你好世界" tkinter脚本,但导入了一些项目测试Pyinstaller所需的依赖项。我正在运行Yosemite 10.10.5的Mac上。 这是我的剧本:

#!/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示例时,也会发生此错误。我在// anaconda / lib中有libpython2.7.dylib文件,我试图将它链接到usr / lib / using

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

但是它没有解决问题...

2 个答案:

答案 0 :(得分:1)

首先,我看到你正在使用conda。我在Mac上遇到了完全相同的问题,特别是:

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

尝试部署我在conda环境中放置的应用程序。

经过大量的谷歌搜索和阅读后,我发现当前的PyInstaller并没有很好地处理带有@rpath引用的动态库。您可以通过在Python二进制文件上运行“otool -L”来确认库引用是否使用@rpath,对于您来说看起来像// anaconda / bin / python(可能是//anaconda/bin/python2.7的链接)

幸运的是,最近在conIn的PyInstaller的一个分支上解决了这个问题。特定补丁位于https://github.com/conda-forge/pyinstaller-feedstock/pull/2

我使用这个分叉版本所做的是卸载我在conda环境中通过pip下载的PyInstaller,然后使用https://github.com/conda-forge/pyinstaller-feedstock中的指令在我的conda环境中使用这个PyInstaller的分支。具体来说,这些命令:

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

所以我建议专门针对conda环境切换到这个修补版本的PyInstaller,看看它是否可以帮助你解决问题,就像它对我一样。

答案 1 :(得分:1)

如果您通过像我这样的pyenv使用python,则可能需要重新安装并启用共享才能访问xcode库,除非您之前已经这样做。

sudo env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7

PS:我在达尔文(Darwin)上工作,但enable-sharedenable-framework有用

实际上,下面的错误消息告诉我们该怎么做

enter image description here

相关问题