简体   繁体   中英

How to create executable file on mac from python script developed on windows

I admit at the beginning that I am a novice python developer, so I apologize in advance for questions that may seem stupid.

I prepared python script with GUI (Tkinter), which use plenty external libraries. I'm working on Windows. Currently, I share my program in the form of an .exe file for Windows users, who do not have Python installed on their PCs. Everything works.

Recently I received a query if I can compile my code on an executable file that is usable for Mac users.

I have a number of questions related to this: 1) can I do it from a PC with Windows or i need Mac? I guess I have to have access to a Mac. 2) will my code work on mac without any editing? What about external libraries? Do you know any easy way to copy/paste my "python with used libraries" from Windows to Mac? 3) will I create a executable file in the same way as Windows, I mean I will use a "Pyinstaller" type library?

Thank you in advance for your help.

1) can I do it from a PC with Windows or i need Mac? I guess I have to have access to a Mac.

You can use a virtual machine and build for mac.

2) will my code work on mac without any editing? What about external libraries? Do you know any easy way to copy/paste my "python with used libraries" from Windows to Mac?

Some libraries have different behavior between macOS and Windows, yes. You should consult the documentation for the libraries you are using.

3) will I create a executable file in the same way as Windows, I mean I will use a "Pyinstaller" type library?

If you're actually using pyinstaller then it is compatible with both mac and windows. You have to check that the library you're using is compatible with both by looking at their docs.


An example of this is to use virtualbox mac image.

Install virtualbox (see this )

Install MacOS (see this )

Install the correct python (obviously python.org )

git clone your repository

Setup your virtual environment (or just pip install -r requirements.txt with your requirements file but I'm a stickler about venvs)

Note: I know you said pyinstaller -like but pyinstaller has a note about macos.

Build!

You shouldn't have any trouble. Just make sure the version of python is the same, as I believe the default on mac is 2.7.

Also, python scripts aren't compiled, rather interpreted, so making the file executable doesn't really mean it's a binary file in this case. I'm not sure what method you used to run python on a computer that doesn't have python on it, as there are a few, but if you can manage to do that on windows, it should work on mac.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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