简体   繁体   English

在Mac上使用cx_Freeze从.py创建.exe

[英]Creating a .exe from a .py using cx_Freeze on a Mac

I'm trying to create an executable file that I can run on Windows from a python file. 我正在尝试创建一个可在Windows上从python文件运行的可执行文件。 I'm using a Mac and and trying to do this using cx_Freeze. 我正在使用Mac,并尝试使用cx_Freeze执行此操作。 I have a folder with 2 files in it: pyTest.py and setup.py. 我有一个包含2个文件的文件夹:pyTest.py和setup.py。 Here is the contents of pyTest.py: 这是pyTest.py的内容:

import numpy as np

print(np.sqrt(2))

here is the contents of setup.py: 这是setup.py的内容:

import sys
from cx_Freeze import setup, Executable


build_exe_options = {"packages": ['numpy'],
                     "excludes": ['Tkinter', 'tcl', 'ttk']}


base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(name='test1',
      version='0.1', 
      description='test',
      options = { "build_exe" : build_exe_options},
      executables = [Executable('pyTest.py', base=base)])

when I run the terminal python setup.py build , a folder called "build" is created which contains only another folder called "exe.macosx-10.6-intel-2.7" which contains a folder called "lib", libncursesw.5, pyTest, Python. 当我运行终端python setup.py build ,将python setup.py build一个名为“ build”的文件夹,其中仅包含另一个名为“ exe.macosx-10.6-intel-2.7”的文件夹,其中包含一个名为“ lib”,libncursesw.5,pyTest的文件夹,Python。 pyTest and Python are both Unix executables. pyTest和Python都是Unix可执行文件。 I am using a second computer which has Windows 10 which I am trying to use to run the .exe file I'm trying to make. 我正在使用第二台装有Windows 10的计算机,该计算机试图用来运行我要制作的.exe文件。 I tried running the pyTest file but it does not work. 我尝试运行pyTest文件,但是它不起作用。

From the post in the "Linked" category : 从“链接”类别中的帖子中:

" Freezing for other platforms 冻结其他平台

cx_Freeze works on Windows, Mac and Linux, but on each platform it only makes an executable that runs on that platform. cx_Freeze可在Windows,Mac和Linux上运行,但是在每个平台上,它仅生成在该平台上运行的可执行文件。 So if you want to freeze your program for Windows, freeze it on Windows; 因此,如果要冻结Windows程序,请在Windows上冻结它。 if you want to run it on Macs, freeze it on a Mac. 如果要在Mac上运行,请在Mac上冻结它。

At a pinch, you can try to make a Windows executable using Wine. 您可以尝试使用Wine制作Windows可执行文件。 Our experience is that you need to copy some files in manually after cx_Freeze has run to make the executable work. 我们的经验是,您需要在cx_Freeze运行后手动复制一些文件,以使可执行文件起作用。 We don't recommend this option. 我们不建议使用此选项。 "

Have been trying all morning too, this is kinda disappointing. 整个上午也都在尝试,这有点令人失望。 Maybe I'll use py2exe 也许我会用py2exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM