gpt4 book ai didi

python - 使用 aptitude 安装包时的多个版本的 python

转载 作者:太空宇宙 更新时间:2023-11-03 13:04:25 25 4
gpt4 key购买 nike

在一台我不能随便破坏东西的实验室机器上,似乎安装了不止一个版本的 python。

如果我使用 python --version 我会看到 2.7.1。

我已经通过“apt-get install numpy”安装了 numpy,它说它已安装,但是当我尝试导入它时却找不到。

当我在机器上查找 numpy 时,我在/usr/lib/python2.5/site-packages/numpy 文件夹中看到它。我认为这就是问题所在……apt-get 将它放在 2.5 版本而不是 2.7 中。

我该如何解决这个问题?有没有办法告诉 apt-get 我在安装时谈论的是哪个 python?还是放弃 aptitude 并使用 pip 之类的东西?

最佳答案

如果你想在一台机器上使用多个版本的python,你应该调查virtualenv .

virtualenv is a tool to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can't install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtualenv can help you. It creates an environment that has its own installation directories, that doesn't share libraries with other virtualenv environments (and optionally doesn't access the globally installed libraries either).

这里有个问题with a similar solution .

此外,我使用virtualenvwrapper因为我发现管理多个环境让​​生活变得更轻松。

关于python - 使用 aptitude 安装包时的多个版本的 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8964736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com