简体   繁体   English

在Mac上运行Windows中编写的python脚本

[英]Running python script written in windows on mac

Iv'e written simple python script in the windows version. 我在Windows版本中编写了简单的python脚本。 written in python 2.7, code compatible to 3.4 runs as script with #! 用python 2.7编写,与#3.4兼容的代码以#!作为脚本运行! /usr/bin/python / usr / bin / python

Will it run as is on mac? 它可以在Mac上按原样运行吗? Would like to know this before i distribute it to mac users and don't have a mac machine to test it. 在我将其分发给Mac用户并且没有Mac机器进行测试之前,想知道这一点。

You should use #!/usr/bin/env python as your first line in the script. 您应该使用#!/usr/bin/env python作为脚本的第一行。 It will be applied when you make the script executable and run it like ./script.py 当您使脚本可执行并像./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. python中的大多数基本操作可在操作系统之间移植。 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. 使用提供的包(例如import os )来执行平台相关的工作。 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) 在许多情况下,取决于硬件配置等,在一个系统上运行的代码可能不会在另一个系统上运行。pp(我想到了多线程,pyopenCL等)

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

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