迁移到 Python 2.6.x

发布于 2024-08-03 16:49:14 字数 194 浏览 6 评论 0原文

我的东西是在 Python 2.5.2 上开发和运行的,

我想将一些代码移动到 3.x,但这是不可行的,因为我使用的许多外部包还不存在。 (例如 numpy)。

因此,我将执行中间步骤并转到 2.6.2。

我的问题:如果外部模块在 2.5.2 上运行,但没有明确声明它可以在 2.6.x 上运行,我可以假设它会没问题吗?或不?

My stuff is developed and running on Python 2.5.2

I want to move some code to 3.x, but that isn't feasible because so many of the external packages I use are not there yet. (Like numpy for instance).

So, I'll do the intermediate step and go to 2.6.2.

My question: If an external module runs on 2.5.2, but doesn't explicitly state that it works with 2.6.x, can I assume it'll be fine? Or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爱的十字路口 2024-08-10 16:49:14

他们很可能会工作得很好。有些东西可能会导致 DeprecationWarnings,例如 sha 模块,但可以安全地忽略它们。这是我的直觉,当然你可能会遇到一些导致问题的具体事情。无论如何,快速浏览一下这些应该很快就能知道您的代码是否需要工作:

Most likely they will work just fine. Some things might cause DeprecationWarnings, for example sha module, but they can be ignored safely. This is my gut feeling, of course you can hit some specific thing causing problems. Anyway, a quick look over these should tell pretty fast whether your code needs work or not:

淡淡的优雅 2024-08-10 16:49:14

主要问题将与您可能使用的任何 C 编码扩展有关:取决于您的系统,但尤其是在 Windows 上,为 2.5 编译的此类扩展可能根本无法工作(或者至少不能安静且可靠地工作) 2.6。这与过去从 2.4 迁移到 2.5 没有什么特别不同。

最简单的解决方案(恕我直言)是获取任何此类扩展的源代码并重新安装它们。在大多数平台上,对于大多数扩展,python setup.py install(可能使用 sudo 或以管理员身份登录,具体取决于您的安装)将起作用 - 您可以需要下载并安装适当的“开发人员”软件包,这又取决于您正在使用的系统以及您已经安装的内容(例如,在 Mac OS X 上,您需要安装 XCode——或者至少是其中的 gcc 子集,但最简单的方法是全部安装——这又要求您在 Apple Developer Connection 上免费注册并下载大型 XCode 包)。

我不确定目前这种方法在 Windows 上有多方便——即,您是否可以使用免费的编译器,例如 mingw 或 Microsoft 的“express”版本的 VS,或者必须付费$$ 到 MS 以获得正确的编译器。然而,大多数第三方扩展的开发人员确实会提供现成的 Windows 二进制文件,正是因为让用户重新编译在 Windows 上(或者至少曾经是)很麻烦,而且 2.6 已经得到了第三方的广泛支持扩展维护者(因为毕竟这对他们来说也只是一个简单的重新编译;-),所以你可能很幸运,发现你需要的所有预编译二进制文件已经可用于你使用的扩展。

The main issue will come with any C-coded extensions you may be using: depending on your system, but especially on Windows, such extensions, compiled for 2.5, are likely to not work at all (or at least not quietly and reliably) with 2.6. That's not particularly different from, e.g., migrating from 2.4 to 2.5 in the past.

The simplest solution (IMHO) is to get the sources for any such extensions and reinstall them. On most platforms, and for most extensions, python setup.py install (possibly with a sudo or logged in as administrator, depending on your installation) will work -- you may need to download and install proper "developer" packages, again depending on what system exactly you're using and what you have already installed (for example, on Mac OS X you need to install XCode -- or at least the gcc subset thereof, but it's simplest to install it all -- which in turn requires you to sign up for free at Apple Developer Connection and download the large XCode package).

I'm not sure how hassle-free this approach is on Windows at this time -- i.e., whether you can use free-as-in-beer compilers such as mingw or Microsoft's "express" edition of VS, or have to shell out $$ to MS to get the right compiler. However, most developers of third party extensions do go out on their way to supply ready Windows binaries, exactly because having the users recompile is (or at least used to be) a hassle on Windows, and 2.6 is already widely supported by third-party extension maintainers (since after all it IS just about a simple recompile for them, too;-), so you may be in luck and find all the precompiled binaries you need already available for the extensions you use.

别在捏我脸啦 2024-08-10 16:49:14

你不能这样假设。但是,您应该能够轻松测试它是否有效。

另外,不要费心尝试再过一两年迁移到 3.x。 2.6 已经向后移植了 3.0 的许多功能,因此一旦完成,过渡不会那么糟糕。

You can't assume that. However, you should be able to easily test if it works or not.

Also, do not bother trying to move to 3.x for another year or two. 2.6 has many of 3.0's features back-ported to it already, so the transition won't be that bad, once you do make it.

乜一 2024-08-10 16:49:14

2.6 文档的新增内容部分可能值得阅读。虽然 2.6 被设计为向后兼容,但有一些更改可能会捕获代码,特别是正在执行某些奇怪操作的代码(例如: hasattr() 曾经用来吞掉所有错误,现在它吞掉了除SystemExitKeyboardInterrupt;大多数人不会注意到,但可能有一些奇怪的代码会产生影响)。

此外,该代码还表明您可以进行一些更改,以便在读取包时更容易迁移到 3.x(例如区分 str 和 bytes,即使它们在 2.6 中是同义词)。

It is probably worth reading the What's New section of the 2.6 documentation. While 2.6 is designed to be backwards compatible, there are a few changes that could catch code, particular code that is doing something odd (example: hasattr() used to swallow all errors, now it swallows all but SystemExit and KeyboardInterrupt; not something that most people would notice, but there may be odd code where it would make a difference).

Also, that code indicates changes you can make going forward that will make it easier to move to 3.x when your packages are read (such as distinguishing between str and bytes even though they are synonyms in 2.6).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文