在特定的Python版本上安装软件包 [英] Installing packages on a specific Python version

查看:122
本文介绍了在特定的Python版本上安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Ubuntu 14.04系统上同时安装了Python 3.3和3.4.当我使用pip3安装Python软件包时,例如numpy

sudo pip3 install numpy

仅将其安装在Python 3.4上.如何在Python 3.3上也安装它?

谢谢!

解决方案

每个Python安装都有其自己的单独站点包.

因此,如果要同时安装两者,则必须安装两次.做到这一点的方法是使用pip3.3pip3.4而不是仅仅使用pip3. (当然,如果您没有pip3.3,则必须安装它.)


您可能想知道为什么每个Python安装都有自己的单独站点包.

部分原因是,较新的Python版本通常具有新功能,并且允许安装程序根据您的Python版本安装不同的东西.这不是很常见,但是软件包没有真正的方法来表明它将针对不同的版本执行不同的操作,因此setuptools必须假定它们都将起作用.

.pyc编译的字节码也可以在版本之间进行更改,即使模块没有做任何不同的事情.

但是,传统上最大的问题是二进制C扩展模块.通常,针对一个libpython编译的模块不能与其他Python版本一起使用.但是,对于3.3+,情况并非总是如此-仅使用稳定" API的模块可以针对3.3进行编译,并且仍可以在3.4中使用(当然,假定使用相同的平台和构建设置). /p>


Python正在逐步发展以处理可在安装之间共享的编译模块(.pyc和.so),但还不存在.

如果您偶然知道(或愿意测试)它们的兼容性,则可以始终设置一个额外的shared-site-packages目录,将3.3配置为安装到该目录,并同时配置3.3和3.4看一下.但是,这通常比其价值还多.

I currently have both Python 3.3 and 3.4 installed on my Ubuntu 14.04 system. When I install a Python package using pip3, for instance numpy,

sudo pip3 install numpy

it only installs it on Python 3.4. How can I install it on Python 3.3 as well?

Thank you!

解决方案

Each Python installation has its own separate site-packages.

So, if you want to install for both, you have to install it twice. The way to do that is to use pip3.3 and pip3.4 instead of just pip3. (If you don't have pip3.3, you'll have to install it, of course.)


You may be wondering why each Python installation has its own separate site-packages.

Part of the reason is that newer Python versions often have new features, and an installer is allowed to install different things depending on your Python version. This isn't very common, but there's no real way for a package to signal that it's going to do different things for different versions, so setuptools has to assume they all will.

The .pyc compiled bytecode can also change between versions, even without the module doing anything different.

But the biggest problem, traditionally, is binary C extension modules. In general, a module compiled against one libpython won't work with a different Python version. In the case of 3.3+, however, this isn't always true—a module that uses only the "stable" API can be compiled for 3.3 and still work in 3.4 (assuming the same platform and build settings, of course).


Python is gradually evolving to deal with compiled modules (both .pyc and .so) that can be shared between installations, but it's not there yet.

In cases where you happen to know (or are willing to test) that they're compatible, you can always set up an extra shared-site-packages directory, configure your 3.3 to install to that directory, and configure both 3.3 and 3.4 to look at it. However, that's usually more work than it's worth.

这篇关于在特定的Python版本上安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆