2017-02-18 133 views
-2

我正在運行Linux Ubuntu 16.04 LTS。我安裝了pip以加載Python的第三方包。 Python 2.7和3.5.2附帶了我的Linux發行版,但後來我安裝了3.6。現在我正在嘗試安裝Scipy。在scipy.org以下爲SciPy的堆疊安裝的說明,我跑以下命令(以前的PIP安裝後)在終端:Python3上的Scipy安裝

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

問題是,這只是安裝包的Python 2.7,而不是3.5.2或3.6。我如何使安裝程序適用於Python 3.x?非常感謝指導。我的頭髮在這方面變得灰暗,我似乎無法通過谷歌搜索獲得正確的結果。

+1

你是否研究過爲python3安裝pip:'sudo apt-get install python3-pip',然後使用'pip3'(而不是'pip')來安裝你的軟件包? – Akavall

+1

我建議您查看[virtualenv](https://virtualenv.pypa.io/en/stable/)或使用[Anaconda](https://www.continuum.io/downloads)併爲您的不同版本創建環境蟒蛇 – Grr

回答

2

我可以推薦Anaconda嗎? https://www.continuum.io/

Anaconda(又名Conda)是一款支持Windows,Mac和Linux的跨平臺軟件包管理器。它旨在解決其他軟件包管理器的問題(例如,易於安裝,點,distutils)。

康達解決了很多包裝問題。安裝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環境和包裝)。

隨着康達,創造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 <module-name>

注意您仍然可以繼續在同一臺機器上同時運行Python2.x和Python3.x,因此不需要卸載python2.x。

您可以繼續安裝包Python2.x因爲你一直在做,通過使用:

pip install <module-name>

和使用python3.x安裝軟件包:

pip3 install <module-name>

最後,要在您的終端上運行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。

+0

我的榮幸,我很高興能夠幫到你:)。如果答案確實能解決您的問題,您可以將其標記爲正確的答案 - 如果答案確實回答了您的問題,那就是。 –