【问题标题】:Scipy installation on Python3在 Python3 上安装 Scipy
【发布时间】:2017-02-18 22:40:36
【问题描述】:

我正在运行 Linux Ubuntu 16.04 LTS。我安装了 pip 以便为 Python 加载第三方包。 Python 2.7 和 3.5.2 随我的 Linux 发行版一起提供,但我后来安装了 3.6。现在我正在尝试安装 Scipy。按照 scipy.org 上的 Scipy 堆栈安装说明,我在终端中运行了以下命令(在之前的 pip 安装之后):

pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose

问题是这只会安装 Python 2.7 的包,而不是 3.5.2 或 3.6。如何让安装适用于 Python 3.x?非常感谢您的指导。我的头发已经变白了,我似乎无法通过谷歌搜索得到正确的结果。

【问题讨论】:

  • 您是否考虑过为 python3 安装 pip:sudo apt-get install python3-pip,然后使用 pip3(而不是 pip)来安装您的软件包?
  • 我建议查看virtualenv 或使用Anaconda 并为不同版本的python 创建环境

标签: python linux numpy scipy


【解决方案1】:

我可以推荐 Anaconda 吗? https://www.continuum.io/

Anaconda(又名 Conda)是一个跨平台的包管理器,支持 Windows、Mac 和 Linux。它旨在解决其他包管理器(例如easy-install、pip、distutils)的问题。

Conda 解决了很多包装问题。安装 Conda 后,您可以安装所需的软件包,而不必担心它们会失败。您还可以创建“虚拟环境”。您希望 Python2 和 Python3 在同一个系统上吗?完毕。

conda create -n Python2 python=2.7.13
conda create -n Python3 python=3.6.0

要切换到一个,您可以输入:

activate Python2

现在您处于 Python2 环境中。

您可以随意调用环境。

这是一个非常有用的 20 分钟视频,来自 Continuum 的 Aaron Meurer 在 SciPy 2014 上介绍了 Conda。(https://www.youtube.com/watch?v=UaIvrDWrIWM) 我看了这个视频,它永远改变了我的生活(关于 Python 环境和打包)。

使用 Conda,创建 SciPy2 和 SciPy3 环境:

>conda search scipy
Fetching package metadata ...........
scipy                        0.11.0               np17py27_1  defaults
                             0.11.0               np16py27_1  defaults
                             0.11.0               np17py26_1  defaults
                             0.11.0               np16py26_1  defaults
                             0.12.0               np17py26_0  defaults
                             0.12.0               np17py33_0  defaults
                             0.12.0               np17py27_0  defaults
                             0.12.0              np16py27_p0  defaults        [mkl]
                             0.12.0              np17py27_p0  defaults        [mkl]
                                        << Truncated >>
                             0.18.0              np111py34_0  defaults
                             0.18.0              np111py35_0  defaults
                             0.18.0              np111py27_0  defaults
                             0.18.1              np111py35_0  defaults
                             0.18.1              np111py27_0  defaults
                             0.18.1              np111py36_0  defaults
                             0.18.1              np111py34_0  defaults
                             0.18.1              np112py27_1  defaults
                             0.18.1              np111py34_1  defaults
                             0.18.1              np112py36_1  defaults
                             0.18.1              np111py36_1  defaults
                             0.18.1              np112py35_1  defaults
                          *  0.18.1              np111py27_1  defaults
                             0.18.1              np111py35_1  defaults

>conda search python
Fetching package metadata ...........
python                       2.6.8                         5  defaults
                             2.6.8                         6  defaults
                             2.6.9                         0  defaults
                             2.6.9                         1  defaults
                             2.7.3                         2  defaults
                                        << Truncated >>
                             2.7.10                        0  defaults
                             2.7.10                        1  defaults
                             2.7.10                        3  defaults
                             2.7.10                        4  defaults
                             2.7.10                        5  defaults
                             2.7.11                        0  defaults
                             2.7.11                        1  defaults
                             2.7.11                        2  defaults
                             2.7.11                        4  defaults
                             2.7.11                        5  defaults
                             2.7.12                        0  defaults
                          *  2.7.13                        0  defaults
                             3.3.0                         4  defaults
                             3.3.1                         0  defaults
                             3.3.2                         0  defaults
                             3.3.3                         0  defaults
                             3.3.4                         0  defaults
                             3.3.5                         0  defaults
                                        << Truncated >>
                             3.5.1                         0  defaults
                             3.5.1                         1  defaults
                             3.5.1                         2  defaults
                             3.5.1                         4  defaults
                             3.5.1                         5  defaults
                             3.5.2                         0  defaults
                             3.6.0                         0  defaults

>conda create -n SciPy2 python=2.7.13 scipy=0.18.1
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment D:\Applications\Anaconda\envs\SciPy2:

The following NEW packages will be INSTALLED:

    mkl:            2017.0.1-0
    numpy:          1.12.0-py27_0
    pip:            9.0.1-py27_1
    python:         2.7.13-0
    scipy:          0.18.1-np112py27_1
    setuptools:     27.2.0-py27_1
    vs2008_runtime: 9.00.30729.5054-0
    wheel:          0.29.0-py27_0

Proceed ([y]/n)? y

numpy-1.12.0-p 100% |###############################| Time: 0:00:00  10.88 MB/s
scipy-0.18.1-n 100% |###############################| Time: 0:00:00  13.49 MB/s
#
# To activate this environment, use:
# > activate SciPy2
#
# To deactivate this environment, use:
# > deactivate SciPy2
#
# * for power-users using bash, you must source
#


>conda create -n SciPy3 python=3.6.0 scipy=0.18.1
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment D:\Applications\Anaconda\envs\SciPy3:

The following NEW packages will be INSTALLED:

    mkl:            2017.0.1-0
    numpy:          1.12.0-py36_0
    pip:            9.0.1-py36_1
    python:         3.6.0-0
    scipy:          0.18.1-np112py36_1
    setuptools:     27.2.0-py36_1
    vs2015_runtime: 14.0.25123-0
    wheel:          0.29.0-py36_0

Proceed ([y]/n)? y

vs2015_runtime 100% |###############################| Time: 0:00:00   9.96 MB/s
python-3.6.0-0 100% |###############################| Time: 0:00:02  12.86 MB/s
numpy-1.12.0-p 100% |###############################| Time: 0:00:00  13.61 MB/s
setuptools-27. 100% |###############################| Time: 0:00:00  13.15 MB/s
wheel-0.29.0-p 100% |###############################| Time: 0:00:00  18.89 MB/s
pip-9.0.1-py36 100% |###############################| Time: 0:00:00  11.73 MB/s
scipy-0.18.1-n 100% |###############################| Time: 0:00:00  12.76 MB/s
#
# To activate this environment, use:
# > activate SciPy3
#
# To deactivate this environment, use:
# > deactivate SciPy3
#
# * for power-users using bash, you must source
#


>activate SciPy3

(SciPy3) >

注意:我只是在 Windows 上完成的。它在 Mac 和 Linux 上的工作方式相同,但就像它说的那样,使用 Bash 你必须先获取源才能激活。

我希望这对您有所帮助。

【讨论】:

    【解决方案2】:

    正如@Akavall 所提到的,目前您已经安装了一个 Python2.x pip,当您运行此命令pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose 时,您当前正在使用这个 pip 来安装包。要为 Python3.x 安装包,您需要安装一个 Python3.x pip,它被称为 pip3。要安装 pip3,请从终端运行以下命令:

    sudo apt-get install python3-pip

    安装 pip3 后,您可以使用以下命令为您的 python3.x 安装软件包:

    pip3 install &lt;module-name&gt;

    请注意,您仍然可以在同一台机器上继续同时运行 Python2.x 和 Python3.x,无需卸载 python2.x。

    您可以继续安装 Python2.x 的软件包,方法是:

    pip install &lt;module-name&gt;

    并使用以下命令为 python3.x 安装软件包:

    pip3 install &lt;module-name&gt;

    最后,要在终端上运行 Python3.x,您需要输入:

    python3

    而不仅仅是python(指的是python2.x)。例如,如果您有一个名为 Hello.py 的脚本,要使用 Python3.x 从终端执行此脚本,请执行以下操作:

    python3.x Hello.py
    

    要使用 Python2.x 运行相同的脚本,请执行以下操作:

    python2.x Hello.py
    

    或:

    python Hello.py
    

    所以,一句话,pip 指向 python2,而 pip3 指向 python3。见this question for more information

    我希望这能回答你的问题:)。再一次,我只是对@Akavall 上面已经给出的一个很好的评论进行了扩展,所以归功于@Akavall。

    【讨论】:

    • 很高兴,我很高兴能帮上忙 :)。如果答案确实解决了您的问题,您可以将其标记为正确答案 - 如果它确实回答了您的问题,那就是。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2023-04-04
    • 1970-01-01
    • 2016-12-29
    • 2012-08-05
    • 2012-11-08
    • 2010-10-10
    相关资源
    最近更新 更多