在pyenv中使用py2app使用非系统Python构建的应用无法在其他计算机上运行 [英] App built with non-system Python using py2app in pyenv not runnable on other machines
问题描述
我的理解是,只要使用非Apple默认的Python进行构建,最终用户就无需自己安装Python即可执行py2app构建的应用程序.在我自己的环境中开发和测试应用程序时,显然我已经安装了Python.具体来说,我内置了 pyenv 并安装了python.org,而不是Apple自己的.但是,当我将应用程序提供给未安装Python的最终用户时,她会得到:
My understanding was that as long as a non-Apple-default Python is employed to build, that the end-user need not install Python him/herself to execute a py2app-built app. In developing and testing the app in my own environment, I obviously have Python installed. Specifically, I built in a pyenv with with a python.org install, not Apple's own. Yet when I give the app to an end-user who doesn't have Python installed, she gets:
找不到Python运行时.您可能需要安装 Python的框架构建,或在中编辑PyRuntimeLocations数组 此应用程序的Info.plist文件.
A Python runtime could not be located. You may need to install a framework build of Python, or edit the PyRuntimeLocations array in this application's Info.plist file.
第二行涉及;如果陈述正确,则需要为最终用户安装的每个可能位置(例如/usr/bin
,/Library/Frameworks
等)构建一个单独的应用程序实例.
The second line is concerning; if what it states is true, then a separate app instance would need to be built for every possible location of an end-user's install e.g /usr/bin
, /Library/Frameworks
etc.
更新:Info.plist定义:
UPDATE: Info.plist defines:
<key>PythonExecutable</key>
<string>/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python</string
但是,最终用户仅在/usr/bin
中安装了系统.
Yet the end-user in question only has a system install in /usr/bin
.
这是否意味着每个最终用户都需要拥有一个外部安装的Python,并且它必须存在于/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
Does this mean that every end-user needs to have an externally-installed Python, and it must live in /Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
如果他们没有非Apple Python,该怎么办?如果他们有非Apple Python但不是2.6怎么办?如何避免这种某种硬编码的依赖关系?
What if they don't have a non-Apple Python? What if they have a non-Apple Python but it's not 2.6? How can this somewhat hardcoded dependency be avoided?
推荐答案
py2app认为您正在使用系统解释器,则会自动默认为--semi-standalone
模式.您来自Python.org的解释器不应该算作系统"解释器,但是您可以看到py2app
使用此命令的想法:
py2app automatically defaults to --semi-standalone
mode if it thinks you are using the system interpreter. Your interpreter from Python.org shouldn't count as a "system" interpreter, but you could see what py2app
thinks using this command:
$ python -c "import py2app.build_app; print py2app.build_app.is_system()"
False
需要提防的一个问题:今天我安装了Python.org解释器后,bash
并未更新它的hash
缓存,因此在启动python时引起了奇怪的不兼容性.我必须键入hash -r python
来重置缓存,并确保正在使用正确版本的python. (解决此问题的另一种方法是注销并再次登录.)我想可能是同一问题可能导致py2app
对于您是否使用系统python感到困惑.
One issue to watch out for: After I installed a Python.org interpreter today, bash
didn't update it's hash
cache, causing strange incompatibilities when I launched python. I had to type hash -r python
to reset the cache and make sure the correct version of python was getting used. (Another way to fix this is to log out and log in again.) I suppose it's possible that the same issue could have caused py2app
to be confused about whether or not you were using the system python.
如果这不能解决问题,请尝试将python解释器安装到类似~/mypython
之类的怪异位置,以确保无法将它与系统python混淆.
If that doesn't do the trick, then try installing your python interpreter to a weird location, like ~/mypython
or something like that, just to make sure there's no way it can be confused for a system python.
作为最后的手段,我想您可以破解py2app
源代码,以便is_system()
始终返回False
.不过,不确定是否会带来任何不良后果.
As a last resort, I suppose you could just hack the py2app
source code so that is_system()
always returns False
. Not sure if that would have any adverse consequences, though.
PS-这是有关将py2app
与conda
打包的应用程序一起使用的一些教程:
https://github.com/stuarteberg/helloworld 与您的问题并不完全相关,但是您可以进行比较并使用您自己的设置进行查找,并查找任何明显的差异.
PS -- Here's a little tutorial on using py2app
with a conda
-packaged application:
https://github.com/stuarteberg/helloworld Not exactly relevant to your problem here, but you could compare it with your own setup and look for any conspicuous differences.
这篇关于在pyenv中使用py2app使用非系统Python构建的应用无法在其他计算机上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!