简体   繁体   中英

Running python script written in windows on mac

Iv'e written simple python script in the windows version. written in python 2.7, code compatible to 3.4 runs as script with #! /usr/bin/python

Will it run as is on mac? Would like to know this before i distribute it to mac users and don't have a mac machine to test it.

You should use #!/usr/bin/env python as your first line in the script. It will be applied when you make the script executable and run it like ./script.py

Short answer: It might run.

Long answer: OS compatibility is a tricky issue. When writing code, make sure that it is portable as much as possible. Most of the basic operations in python are portable between OSes. When it comes to file reading, writing, enconding handling etc. stuff might go horribly wrong. Use the provided packages (eg import os ) to do platform dependent stuff. In general, there is no way around a test. In many cases, code that runs on one system might not on another depending on hardware configuration etc. pp (I think of multithreading, pyopenCL and the like)

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