OS X安装和使用Anaconda

昨晚想安装sklearn机器学习库,按照官网上推荐的方法(http://scikit-learn.org/stable/install.html#third-party-distributions)我去下了那个叫Anaconda的全家桶(下载地址:https://www.continuum.io/downloads#osx
anaconda下载

把下载的文件放到桌面后,进入desktop目录,敲入下面的命令

MBA-of-Leif:desktop Leif$ bash Anaconda2-4.2.0-MacOSX-x86_64.sh

然后就让你确认条款和安装目录,blahblah..安装完毕。
问题来了,我安装完咋用这东西呢?直接在终端里跑了一个sklearn的示例代码,仍然提示没有sklearn库:

MBA-of-Leif:skl Leif$ python plot_cv_predict.py
Traceback (most recent call last):
  File "plot_cv_predict.py", line 10, in <module>
    from sklearn import datasets
ImportError: No module named sklearn

上sklearn官网确认了一下安装教程,发现:

If you already have a working installation of numpy and scipy, the
easiest way to install scikit-learn is using pip

pip install -U scikit-learn

or conda:

conda install scikit-learn

然而以上两条命令我都试了一遍却都无法执行:

MBA-of-Leif:skl Leif$ conda install scikit-learn
-bash: conda: command not found
MBA-of-Leif:~ Leif$ pip install -U scikit-learn
-bash: pip: command not found

上网一通找anaconda 的使用方法,大部分都是关于windows,linux的。最后终于在stackoverflow上找到了解决办法,原来是环境变量的原因
http://stackoverflow.com/questions/18675907/how-to-run-conda):

With the most recent version of anaconda, you might want to try this:

export PATH=~/anaconda2/bin:$PATH

and then

conda --v

to confirm that it worked.

按照上述方法试过后,再运行示例代码,成功。

注:关于“环境变量”的解释

环境变量(environment
variables)一般是指在操作系统中用来指定操作系统运行环境的一些参数,如:临时文件夹位置和系统文件夹位置等。
环境变量是在操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息。例如Windows和DOS操作系统中的path环境变量,当要求系统运行一个程序而没有告诉它程序所在的完整路径时,系统除了在当前目录下面寻找此程序外,还应到path中指定的路径去找。用户通过设置环境变量,来更好的运行进程。

最后贴几个我在找解决方法的过程中遇到的几个与此相关的对大家可能有帮助的链接:
http://blog.csdn.net/muzilanlan/article/details/50479931(PyCharm 安装 NumPy,SciPy 等科学计算包 (Anaconda)for mac OS X)
http://www.cnblogs.com/baiyangcao/p/anaconda_basic.html(Anaconda使用入门)
http://conda.pydata.org/docs/test-drive.html(用conda管理packag的官网教程)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章