在 Windows 机器上与 Linux 上运行 python

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3765178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:38:34  来源:igfitidea点击:

Running python on a Windows machine vs Linux

pythonwindows

提问by Luke101

I am interested in learning python but my Linux skills suck. I would like to develop a medium to large scale web application using python and django but afraid the software may not work well on a windows box. Is there a performance difference in running python on Linux vs Windows? Is there anything that I should watch out for when developing the application. Also, I am aware that it is very easy integrating C++ libraries with python. Is this statement still true is the code is on a windows box?

我对学习 python 感兴趣,但我的 Linux 技能很烂。我想使用 python 和 django 开发一个中型到大型的 Web 应用程序,但担心该软件可能无法在 Windows 机器上正常运行。在 Linux 和 Windows 上运行 python 有性能差异吗?开发应用程序时有什么我应该注意的地方。另外,我知道将 C++ 库与 python 集成非常容易。如果代码在 Windows 框中,此声明仍然正确吗?

采纳答案by aaronasterling

Don't tell anybody this, but I've run python/django on windows. It works all right and the performance hit isn't any worse than you would expect from windows. I used MySQL and it installed without a problem. I had to grope around to find out how to manage it (no good ol' sudo /etc/init.d/mysql restartbut i eventually found a graphical interface to do what I needed.

不要告诉任何人,但我已经在 Windows 上运行了 python/django。它工作正常,性能下降并不比您对 Windows 的预期更糟。我使用了 MySQL,它安装没有问题。我不得不四处摸索以找出如何管理它(不好,sudo /etc/init.d/mysql restart但我最终找到了一个图形界面来做我需要的事情。

回答by Lie Ryan

Python program is very easily portable. Most of the time your code will work on any platform that have the appropriate version of python.

Python 程序非常容易移植。大多数情况下,您的代码可以在任何具有适当 Python 版本的平台上运行。

One point to be aware of though, is file path handling. Linux, Windows, Macs, etc uses different path schemes, so you shouldn't be handling them as strings; instead use os.path functions to join, split, etc.

但是要注意的一点是文件路径处理。Linux、Windows、Mac 等使用不同的路径方案,因此您不应将它们作为字符串处理;而是使用 os.path 函数来连接、拆分等。

There is ultimately some slight performance difference with regard to timing, threading, processing, I/O, but they're nothing to worry about.

最终在时序、线程、处理、I/O 方面存在一些细微的性能差异,但它们无需担心。

Integrating Python and C++ is easy; the only problem is in the C++ side, i.e. you will have to recompile the C++ code.

集成 Python 和 C++ 很容易;唯一的问题是在 C++ 方面,即您必须重新编译 C++ 代码。

回答by knitti

Shouldn't be a problem. Some people even host Python+Django on Windows.

应该不是问题。有些人甚至在 Windows 上托管 Python+Django。

回答by dekomote

I've been working Py on both Windows and Linux. I favor Linux because of several things:

我一直在 Windows 和 Linux 上使用 Py。我喜欢 Linux 有几个原因:

  1. virtualenvs - once you start working with virtualenvs, there is no turning back.
  2. SHELL - CMD is very frustrating when executing python/management commands in django. Also, you should add python.exe every time :).
  3. ipython works better on Linux.
  4. GeoDjango doesn't work on Vista/7 last time i checked. I spent 3 days trying to set it up. Just for comparison, i set GeoDjango-able development environment in 20 minutes in Linux.
  5. Linux is free :)
  6. Although there is no visible performance impact or incompatibility when working python cross-platform, the benefits of Linux for python development outweigh Windows by a lot. It's a lot more comfortable and definitely will boost your productivity.
  7. ...
  1. virtualenvs - 一旦你开始使用 virtualenvs,就没有回头路了。
  2. SHELL - 在 django 中执行 python/管理命令时,CMD 非常令人沮丧。此外,您应该每次都添加 python.exe :)。
  3. ipython 在 Linux 上运行得更好。
  4. 我上次检查时 GeoDjango 在 Vista/7 上不起作用。我花了 3 天时间尝试设置它。为了比较,我在 20 分钟内在 Linux 中设置了支持 GeoDjango 的开发环境。
  5. Linux 是免费的 :)
  6. 尽管在 python 跨平台工作时没有明显的性能影响或不兼容,但 Linux 对 python 开发的好处远远超过 Windows。它更舒适,肯定会提高您的工作效率。
  7. ...

IMHO Linux is the smart choice for Python development.

恕我直言,Linux 是 Python 开发的明智选择。

回答by hhafez

  1. Which software are you affraid will not work on windows, the actual web app or your development enviroment. If you mean the IDE, then I wouldn't worry about that there are very good python IDEs for windows, as for the webapp that's another discussion all together

  2. The statement that "it is very easy integrating C++ libs with python" is not accurate, there are many ways of doing it and they are not all easy, I have personally only tried SWIG, but there are many other alternatives (for example Boost.Python), whoever I wouldn't believe it is as easy to get up and running with some of these tools on a windows enviromeny with out something like mingw or cygwin as at least SWIG is built with *nix in mind

  1. 您害怕哪种软件在 Windows、实际的 Web 应用程序或您的开发环境中无法运行。如果您指的是 IDE,那么我不会担心 Windows 有非常好的 Python IDE,至于 webapp,这是另一个讨论

  2. “将 C++ 库与 python 集成很容易”的说法并不准确,有很多方法可以做到,而且它们并不容易,我个人只尝试过 SWIG,但还有许多其他替代方案(例如 Boost.C++ 库)。 Python),无论谁我都不相信在 Windows 环境中使用这些工具中的一些工具启动和运行而没有像 mingw 或 cygwin 这样的东西那么容易,因为至少 SWIG 是用 *nix 构建的

回答by S.Lott

but afraid the software may not work well on a windows box.

但担心该软件可能无法在 Windows 机器上正常运行。

Your software will work. The Windows OS may not work as you hope. But that's Windows, not Python.

你的软件会工作。Windows 操作系统可能无法如您所愿。但那是 Windows,而不是 Python。

We develop 100% on Windows. We completely test: Unit test, integration test and user acceptance test on Windows. 100%.

我们 100% 在 Windows 上开发。我们全面测试:在 Windows 上进行单元测试、集成测试和用户验收测试。100%。

We deploy for production 0% on Windows, 100% on Linux.

我们在 Windows 上部署生产 0%,在 Linux 上部署 100%。

We have a few (less than 6) differences in the unit tests that are Windows-specific.

我们在特定于 Windows 的单元测试中有一些(少于 6 个)差异。

The application has no changes. It works with Apache or not. It works with SQLite or MySQL.

应用程序没有任何变化。它是否适用于 Apache。它适用于 SQLite 或 MySQL。