简体   繁体   English

Windows中编写的python代码在Linux中可以工作吗?

[英]will python code written in windows work in linux?

I would like to write some Python code in Windows using QtPy. 我想使用QtPy在Windows中编写一些Python代码。 But before I do that I'd like to know that I can use the code I wrote in Python. 但是在我这样做之前,我想知道我可以使用在Python中编写的代码。 I understand that the complied program won't work due to different platforms but will there be any issues with regards to the *.py files I write in windows vs linux? 我知道该编译程序由于平台不同而无法运行,但是我在Windows vs linux中编写的* .py文件是否存在任何问题?

I've been trying to install QtPy on my Mint installation and I just don't know what the problem is. 我一直在尝试在我的Mint安装上安装QtPy,但我只是不知道问题是什么。 Which is why I wanna go this route. 这就是为什么我想走这条路。

I'd also like my code to work on the raspberry pi. 我也希望我的代码可以在树莓派上工作。

Could you guys advise me to this end? 你们可以建议我这样做吗?

Thanks! 谢谢!

Mostly, yes, as long as you keep to using the tools Python provides you and don't write code that is platform specific. 通常,是的,只要您继续使用Python提供的工具,并且不编写平台特定的代码即可。

Use os.path.join() to build paths, for example. 例如,使用os.path.join()构建路径。 Open files in binary mode when you deal with binary data, text mode when it's text data. 当处理二进制数据时,以二进制模式打开文件;当文本数据为文本模式时,以文本模式打开文件。 Etc. 等等。

Python code itself is platform agnostic; Python代码本身与平台无关; the interpreter on Linux can read python code written on Windows just fine and vice versa. Linux上的解释器可以读取Windows上编写的python代码,反之亦然。

The general rule of thumb is to pay attention to the documentation of the modules you are using; 一般的经验法则是注意所用模块的文档。 any platform specific gotchas should be documented. 任何平台特定的陷阱都应记录在案。

It depends on what your code does. 这取决于您的代码做什么。 Most packages work in both windows and linux however some such as signal only work in windows and are not portable. 大多数软件包都可以在Windows和Linux中使用,但是有些软件包(例如信号)只能在Windows中使用,并且不能移植。 But in the python docs it will say what platforms a given package works in. 但是在python文档中,它将说明给定软件包在哪些平台上工作。

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

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