简体   繁体   English

多个python安装-设置路径变量

[英]Multiple python installations - setting path variable

I have several python installations on my system, in /usr/lib/ I have python2.7, python 3, python3.2. 我的系统上有几个python安装程序,在/ usr / lib /中,我有python2.7,python 3和python3.2。 I am trying to upgrade my version of scipy from .9. 我正在尝试从.9升级我的scipy版本。 When I do a 当我做一个

sudo pip install --upgrade scipy

It doesn't work saying that it's already done in /usr/local/lib/python3.2/dist-packages 说它已经在/usr/local/lib/python3.2/dist-packages中完成了,这是行不通的

When I import it in ipython, however, it finds the old version of Scipy: 但是,当我在ipython中导入它时,它会找到Scipy的旧版本:

/usr/lib/python2.7/dist-packages/scipy/__init__.pyc

How do I tell python to load the 3.2 version of scipy and not the 2.7? 如何告诉python加载3.2版本的scipy而不是2.7版本? I believe this has something to do with the PYTHONPATH variable, but I'm not sure which one to change. 我相信这与PYTHONPATH变量有关,但是我不确定要更改哪个变量。

James 詹姆士

How do I tell python to load the 3.2 version of scipy and not the 2.7 我如何告诉python加载3.2版本的scipy而不是2.7版本

Every python version manages its own set of installed modules. 每个python版本都管理自己的一组已安装模块。 The idea is to invoke the pip executable that belongs to the right python version. 这个想法是调用属于正确python版本的pip可执行文件。

From what you described it seems that you have installed the ipython module in your python2.7 interpreter, but your pip executable belongs to the python3.2 interpreter. 从您的描述看来,您似乎已在python2.7解释器中安装了ipython模块,但您的pip可执行文件属于python3.2解释器。

The easiest way to execute python2.7 's pip is: 执行python2.7pip的最简单方法是:

sudo ipython -m pip install --upgrade scipy

However this installs scipy as root into your system files and thus usually interferes with versions installed by package managers. 但是,这会将scipy作为root用户安装到系统文件中,因此通常会干扰软件包管理器安装的版本。

An arguably better way is to install packages in your user's home directory. 一种可能更好的方法是在用户的主目录中安装软件包。

ipython -m pip install --upgrade scipy --user

As pointed out in the comments, probably the best way is to get familiar with virtualenv . 正如评论中指出的那样,可能最好的方法是熟悉virtualenv

I myself find anaconda particularly appealing, since it comes with a clean way of installing and managing multiple python interpreters with a focus on scientific packages across many platforms. 我本人觉得anaconda特别吸引人,因为它带有一种干净的安装和管理多个python解释器的方式,重点是跨多个平台的科学软件包。

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

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