Anaconda是一套Python的发行版,发行版集成了必要的库,使用户可以一次性完成安装.Anaconda是一个侧重于数据分析的发行版,一些有助于数据分析的库,比如Numpy,Matplotlib,SciPy等都包括于其中,下面介绍如何在ubuntu18.04上安装anaconda.
安装过程可能并不复杂,但是细节很多,下面开始技术流水帐:
1.下载安装包
访问anaconda官网的下载通道
https://www.anaconda.com/products/individual#Downloads
最新版是给小白鼠用的,我不想做小白鼠,所以选择往期版本:
https://repo.anaconda.com/archive/
我们选择支持python3.5的anaconda.
Anaconda3-4.1.1-Linux-x86_64.sh 406.3M 2016-07-08 11:20:02 d0dc08d241f83ffc763504db50008e5b
下载后:
增加可执行权限:
sudo chmod a+x Anaconda3-4.1.1-Linux-x86_64.sh
2.安装:
执行sudo ./Anaconda3-4.1.1-Linux-x86_64.sh
czl@czl-RedmiBook-14:~/anaconda$ sudo ./Anaconda3-4.1.1-Linux-x86_64.sh
Welcome to Anaconda3 4.1.1 (by Continuum Analytics, Inc.)
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>
================
Anaconda License
================
Copyright 2016, Continuum Analytics, Inc.
All rights reserved under the 3-clause BSD License:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Continuum Analytics, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL CONTINUUM ANALYTICS, INC. BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
Notice of Third Party Software Licenses
=======================================
Anaconda contains open source software packages from third parties. These
are available on an "as is" basis and subject to their individual license
agreements. These licenses are available in Anaconda or at
http://docs.continuum.io/anaconda/pkg-docs . Any binary packages of these
third party tools you obtain via Anaconda are subject to their individual
licenses as well as the Anaconda license. Continuum reserves the right to
change which third party tools are provided in Anaconda.
In particular, Anaconda contains re-distributable, run-time, shared-library
files from the Intel (TM) Math Kernel Library ("MKL binaries"). You are
specifically authorized to use the MKL binaries with your installation of
Anaconda. You are also authorized to redistribute the MKL binaries with
Anaconda or in the conda package that contains them. If needed,
instructions for removing the MKL binaries after installation of Anaconda
are available at http://www.continuum.io.
Cryptography Notice
===================
This distribution includes cryptographic software. The country in which you
currently reside may have restrictions on the import, possession, use,
and/or re-export to another country, of encryption software. BEFORE using
any encryption software, please check your country's laws, regulations and
policies concerning the import, possession, or use, and re-export of
encryption software, to see if this is permitted. See the Wassenaar
Arrangement <http://www.wassenaar.org/> for more information.
Continuum Analytics has self-classified this software as Export Commodity
Control Number (ECCN) 5D002.C.1, which includes information security
software using or performing cryptographic functions with asymmetric
algorithms. The form and manner of this distribution makes it eligible for
export under the License Exception ENC Technology Software Unrestricted
(TSU) exception (see the BIS Export Administration Regulations, Section
740.13) for both object code and source code.
The following packages are included in this distribution that relate to
cryptography:
openssl
The OpenSSL Project is a collaborative effort to develop a robust,
commercial-grade, full-featured, and Open Source toolkit implementing the
Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols as
well as a full-strength general purpose cryptography library.
pycrypto
A collection of both secure hash functions (such as SHA256 and RIPEMD160),
and various encryption algorithms (AES, DES, RSA, ElGamal, etc.).
pyopenssl
A thin Python wrapper around (a subset of) the OpenSSL library.
kerberos (krb5, non-Windows platforms)
A network authentication protocol designed to provide strong authentication
for client/server applications by using secret-key cryptography.
cryptography
A Python library which exposes cryptographic recipes and primitives.
Do you approve the license terms? [yes|no]
>>>
Please answer 'yes' or 'no':
>>>
Please answer 'yes' or 'no':
>>> yes
Anaconda3 will now be installed into this location:
/home/czl/anaconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/home/czl/anaconda3] >>>
PREFIX=/home/czl/anaconda3
installing: python-3.5.2-0 ...
installing: _nb_ext_conf-0.2.0-py35_0 ...
installing: alabaster-0.7.8-py35_0 ...
installing: anaconda-client-1.4.0-py35_0 ...
installing: anaconda-navigator-1.2.1-py35_0 ...
installing: argcomplete-1.0.0-py35_1 ...
installing: astropy-1.2.1-np111py35_0 ...
installing: babel-2.3.3-py35_0 ...
installing: backports-1.0-py35_0 ...
installing: beautifulsoup4-4.4.1-py35_0 ...
installing: bitarray-0.8.1-py35_0 ...
installing: blaze-0.10.1-py35_0 ...
installing: bokeh-0.12.0-py35_0 ...
installing: boto-2.40.0-py35_0 ...
installing: bottleneck-1.1.0-np111py35_0 ...
installing: cffi-1.6.0-py35_0 ...
installing: chest-0.2.3-py35_0 ...
installing: click-6.6-py35_0 ...
installing: cloudpickle-0.2.1-py35_0 ...
installing: clyent-1.2.2-py35_0 ...
installing: colorama-0.3.7-py35_0 ...
installing: configobj-5.0.6-py35_0 ...
installing: contextlib2-0.5.3-py35_0 ...
installing: cryptography-1.4-py35_0 ...
installing: curl-7.49.0-0 ...
installing: cycler-0.10.0-py35_0 ...
installing: cython-0.24-py35_0 ...
installing: cytoolz-0.8.0-py35_0 ...
installing: dask-0.10.0-py35_0 ...
installing: datashape-0.5.2-py35_0 ...
installing: decorator-4.0.10-py35_0 ...
installing: dill-0.2.5-py35_0 ...
installing: docutils-0.12-py35_2 ...
installing: dynd-python-0.7.2-py35_0 ...
installing: entrypoints-0.2.2-py35_0 ...
installing: et_xmlfile-1.0.1-py35_0 ...
installing: fastcache-1.0.2-py35_1 ...
installing: flask-0.11.1-py35_0 ...
installing: flask-cors-2.1.2-py35_0 ...
installing: fontconfig-2.11.1-6 ...
installing: freetype-2.5.5-1 ...
installing: get_terminal_size-1.0.0-py35_0 ...
installing: gevent-1.1.1-py35_0 ...
installing: greenlet-0.4.10-py35_0 ...
installing: h5py-2.6.0-np111py35_1 ...
installing: hdf5-1.8.16-0 ...
installing: heapdict-1.0.0-py35_1 ...
installing: idna-2.1-py35_0 ...
installing: imagesize-0.7.1-py35_0 ...
installing: ipykernel-4.3.1-py35_0 ...
installing: ipython-4.2.0-py35_0 ...
installing: ipython_genutils-0.1.0-py35_0 ...
installing: ipywidgets-4.1.1-py35_0 ...
installing: itsdangerous-0.24-py35_0 ...
installing: jbig-2.1-0 ...
installing: jdcal-1.2-py35_1 ...
installing: jedi-0.9.0-py35_1 ...
installing: jinja2-2.8-py35_1 ...
installing: jpeg-8d-1 ...
installing: jsonschema-2.5.1-py35_0 ...
installing: jupyter-1.0.0-py35_3 ...
installing: jupyter_client-4.3.0-py35_0 ...
installing: jupyter_console-4.1.1-py35_0 ...
installing: jupyter_core-4.1.0-py35_0 ...
installing: libdynd-0.7.2-0 ...
installing: libffi-3.2.1-0 ...
installing: libgfortran-3.0.0-1 ...
installing: libpng-1.6.22-0 ...
installing: libsodium-1.0.10-0 ...
installing: libtiff-4.0.6-2 ...
installing: libxml2-2.9.2-0 ...
installing: libxslt-1.1.28-0 ...
installing: llvmlite-0.11.0-py35_0 ...
installing: locket-0.2.0-py35_1 ...
installing: lxml-3.6.0-py35_0 ...
installing: markupsafe-0.23-py35_2 ...
installing: matplotlib-1.5.1-np111py35_0 ...
installing: mistune-0.7.2-py35_0 ...
installing: mkl-11.3.3-0 ...
installing: mkl-service-1.1.2-py35_2 ...
installing: mpmath-0.19-py35_1 ...
installing: multipledispatch-0.4.8-py35_0 ...
installing: nb_anacondacloud-1.1.0-py35_0 ...
installing: nb_conda-1.1.0-py35_0 ...
installing: nb_conda_kernels-1.0.3-py35_0 ...
installing: nbconvert-4.2.0-py35_0 ...
installing: nbformat-4.0.1-py35_0 ...
installing: nbpresent-3.0.2-py35_0 ...
installing: networkx-1.11-py35_0 ...
installing: nltk-3.2.1-py35_0 ...
installing: nose-1.3.7-py35_1 ...
installing: notebook-4.2.1-py35_0 ...
installing: numba-0.26.0-np111py35_0 ...
installing: numexpr-2.6.0-np111py35_0 ...
installing: numpy-1.11.1-py35_0 ...
installing: odo-0.5.0-py35_1 ...
installing: openpyxl-2.3.2-py35_0 ...
installing: openssl-1.0.2h-1 ...
installing: pandas-0.18.1-np111py35_0 ...
installing: partd-0.3.4-py35_0 ...
installing: patchelf-0.9-0 ...
installing: path.py-8.2.1-py35_0 ...
installing: pathlib2-2.1.0-py35_0 ...
installing: patsy-0.4.1-py35_0 ...
installing: pep8-1.7.0-py35_0 ...
installing: pexpect-4.0.1-py35_0 ...
installing: pickleshare-0.7.2-py35_0 ...
installing: pillow-3.2.0-py35_1 ...
installing: pip-8.1.2-py35_0 ...
installing: ply-3.8-py35_0 ...
installing: psutil-4.3.0-py35_0 ...
installing: ptyprocess-0.5.1-py35_0 ...
installing: py-1.4.31-py35_0 ...
installing: pyasn1-0.1.9-py35_0 ...
installing: pycosat-0.6.1-py35_1 ...
installing: pycparser-2.14-py35_1 ...
installing: pycrypto-2.6.1-py35_4 ...
installing: pycurl-7.43.0-py35_0 ...
installing: pyflakes-1.2.3-py35_0 ...
installing: pygments-2.1.3-py35_0 ...
installing: pyopenssl-0.16.0-py35_0 ...
installing: pyparsing-2.1.4-py35_0 ...
installing: pyqt-4.11.4-py35_3 ...
installing: pytables-3.2.2-np111py35_4 ...
installing: pytest-2.9.2-py35_0 ...
installing: python-dateutil-2.5.3-py35_0 ...
installing: pytz-2016.4-py35_0 ...
installing: pyyaml-3.11-py35_4 ...
installing: pyzmq-15.2.0-py35_1 ...
installing: qt-4.8.7-3 ...
installing: qtconsole-4.2.1-py35_0 ...
installing: qtpy-1.0.2-py35_0 ...
installing: readline-6.2-2 ...
installing: redis-3.2.0-0 ...
installing: redis-py-2.10.5-py35_0 ...
installing: requests-2.10.0-py35_0 ...
installing: rope-0.9.4-py35_1 ...
installing: ruamel_yaml-0.11.7-py35_0 ...
installing: scikit-image-0.12.3-np111py35_1 ...
installing: scikit-learn-0.17.1-np111py35_2 ...
installing: scipy-0.17.1-np111py35_1 ...
installing: setuptools-23.0.0-py35_0 ...
installing: simplegeneric-0.8.1-py35_1 ...
installing: singledispatch-3.4.0.3-py35_0 ...
installing: sip-4.16.9-py35_0 ...
installing: six-1.10.0-py35_0 ...
installing: snowballstemmer-1.2.1-py35_0 ...
installing: sockjs-tornado-1.0.3-py35_0 ...
installing: sphinx-1.4.1-py35_0 ...
installing: sphinx_rtd_theme-0.1.9-py35_0 ...
installing: spyder-2.3.9-py35_0 ...
installing: sqlalchemy-1.0.13-py35_0 ...
installing: sqlite-3.13.0-0 ...
installing: statsmodels-0.6.1-np111py35_1 ...
installing: sympy-1.0-py35_0 ...
installing: terminado-0.6-py35_0 ...
installing: tk-8.5.18-0 ...
installing: toolz-0.8.0-py35_0 ...
installing: tornado-4.3-py35_1 ...
installing: traitlets-4.2.1-py35_0 ...
installing: unicodecsv-0.14.1-py35_0 ...
installing: werkzeug-0.11.10-py35_0 ...
installing: wheel-0.29.0-py35_0 ...
installing: xlrd-1.0.0-py35_0 ...
installing: xlsxwriter-0.9.2-py35_0 ...
installing: xlwt-1.1.2-py35_0 ...
installing: xz-5.2.2-0 ...
installing: yaml-0.1.6-0 ...
installing: zeromq-4.1.4-0 ...
installing: zlib-1.2.8-3 ...
installing: anaconda-4.1.1-np111py35_0 ...
installing: conda-4.1.6-py35_0 ...
installing: conda-build-1.21.3-py35_0 ...
installing: conda-env-2.5.1-py35_0 ...
Python 3.5.2 :: Continuum Analytics, Inc.
creating default environment...
installation finished.
Do you wish the installer to prepend the Anaconda3 install location
to PATH in your /home/czl/.bashrc ? [yes|no]
[no] >>> yes
Prepending PATH=/home/czl/anaconda3/bin to PATH in /home/czl/.bashrc
A backup will be made to: /home/czl/.bashrc-anaconda3.bak
For this change to become active, you have to open a new terminal.
Thank you for installing Anaconda3!
Share your notebooks and packages on Anaconda Cloud!
Sign up for free: https://anaconda.org
czl@czl-RedmiBook-14:~/anaconda$
根据安装LOG,可以看到,Numpy,Matplotlib,SciPy三个包都自动安装上了。
3.验证
安装结束后,重启系统,打开控制台,输入Python.可以看到系统的默认Python变成了anaconda,而不再是默认系统路径下的Python. 这可以解释为,既然anaconda是Python的一个发行版,类似于Ubuntu是Linux的一个发行版,所以必然存在其它的Python发行版,比如UBUNTU下通过APT 安装的 /usr/bin/python也算是一个发行版,所以,当系统Python从来源的实现变成anaconda之后,之前安装的包可能失效,需要在anaconda下重新安装或者配置。
然后,我们打开anaconda-navigator这个应用
Anaconda 其实是有图形界面的,叫 Anaconda Navigator,打开后的界面如下,可以看到启动launcher中包含三个主要应用,一个是jupyter,qtconsole以及spyder。 spyder是一个编辑器,从安装到使用都做了相关的集成。qtconsole是一个基于QT开发的python图形界面控制台。jupyter notebook,在深度学习中,有好多代码都被做成扩展名为ipynb的文件,这是一个关于jupyter的notebook文件,既可以做说明文档,也可以包含可运行的python代码,jupyter notebook是BS结构,启动时,会先启动一个Web服务器,然后再启动一个浏览器,通过浏览器来访问本机服务,在这里面可以上传,下载,并编写自己的ipynb代码。
打开jupyter,它是一个基于WEB的网页编辑器,同时还具备本地资源管理器的作用。
jupyter notebook非常有用,打开后,可以选择new->python3创建一个python文件,编辑程序,创建cell,并且执行cell中的程序。
运行快捷键Alt+Enter.
jupyterlab中包含一个控制台,功能上相当于一个shell console.
qtconsole则是一个基于QT的Python命令行控制台程序:
spyder就厉害了,它集程序编辑,调试,运行,仿真于一身,是开发人员接触最频繁的一个工具。
下面我们就在spyder中运行一段程序,利用系统预先安装的数学库和绘图包,绘制一幅傅立叶变换的图像
运行上图这段程序,我们有额外安装任何的Python包,这和UBUNTU原生的python环境手搓很多包,解决依赖的方式是很不同的,anaconda更加方便。
如何卸载?
安装好anaconda后,如果像升级版本,那原来的版本怎么卸载呢?
直接删即可 :
rm -fr ~/anaconda3
然后将.bashrc中安装时自动添加的anaconda环境设置删除
下面是卸载后重新安装Anaconda3-5.0.1-Linux-x86_64.sh
4.安装Tensorflow GPU版
安装命令:
pip install tensorflow-gpu
czl@czl-RedmiBook-14:~$ pip install tensorflow-gpu
Collecting tensorflow-gpu
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)",)': /packages/8b/dc/922125284fb70d5ac17a3c3be87d8f1d95908bb5067977e7813bf7b7f712/tensorflow_gpu-1.14.0-cp35-cp35m-manylinux1_x86_64.whl
Downloading https://files.pythonhosted.org/packages/8b/dc/922125284fb70d5ac17a3c3be87d8f1d95908bb5067977e7813bf7b7f712/tensorflow_gpu-1.14.0-cp35-cp35m-manylinux1_x86_64.whl (377.0MB)
100% |████████████████████████████████| 377.0MB 4.7kB/s
Collecting google-pasta>=0.1.6 (from tensorflow-gpu)
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)",)': /simple/google-pasta/
Downloading https://files.pythonhosted.org/packages/a3/de/c648ef6835192e6e2cc03f40b19eeda4382c49b5bafb43d88b931c4c74ac/google_pasta-0.2.0-py3-none-any.whl (57kB)
100% |████████████████████████████████| 61kB 140kB/s
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in ./anaconda3/lib/python3.5/site-packages (from tensorflow-gpu)
Collecting protobuf>=3.6.1 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/3b/f1/728216338c64b3a06e6ad27d39ace5ea31c83dedc303a533700d8bf2aa8f/protobuf-3.17.3-cp35-cp35m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (1.0MB)
100% |████████████████████████████████| 1.0MB 730kB/s
Collecting grpcio>=1.8.6 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/07/ea/398472e896f529d23fb58e33f01298dfc554a341d58f87c1ea5ad817208e/grpcio-1.39.0.tar.gz (21.3MB)
100% |████████████████████████████████| 21.3MB 83kB/s
Requirement already satisfied (use --upgrade to upgrade): wheel>=0.26 in ./anaconda3/lib/python3.5/site-packages (from tensorflow-gpu)
Collecting termcolor>=1.1.0 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Collecting tensorflow-estimator<1.15.0rc0,>=1.14.0rc0 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/3c/d5/21860a5b11caf0678fbc8319341b0ae21a07156911132e0e71bffed0510d/tensorflow_estimator-1.14.0-py2.py3-none-any.whl (488kB)
100% |████████████████████████████████| 491kB 72kB/s
Collecting keras-preprocessing>=1.0.5 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/79/4c/7c3275a01e12ef9368a892926ab932b33bb13d55794881e3573482b378a7/Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42kB)
100% |████████████████████████████████| 51kB 7.5MB/s
Collecting wrapt>=1.11.1 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/82/f7/e43cefbe88c5fd371f4cf0cf5eb3feccd07515af9fd6cf7dbf1d1793a797/wrapt-1.12.1.tar.gz
Collecting gast>=0.2.0 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/ad/b0/a6c8bc1e77409b63755bb0788ac4d497d31b72082de5945c0122259c533e/gast-0.5.2-py3-none-any.whl
Collecting tensorboard<1.15.0,>=1.14.0 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/91/2d/2ed263449a078cd9c8a9ba50ebd50123adf1f8cfbea1492f9084169b89d9/tensorboard-1.14.0-py3-none-any.whl (3.1MB)
100% |████████████████████████████████| 3.2MB 345kB/s
Collecting absl-py>=0.7.0 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/23/47/835652c7e19530973c73c65e652fc53bd05725d5a7cf9bb8706777869c1e/absl_py-0.13.0-py3-none-any.whl (132kB)
100% |████████████████████████████████| 133kB 3.9MB/s
Collecting numpy<2.0,>=1.14.5 (from tensorflow-gpu)
Downloading https://files.pythonhosted.org/packages/3a/be/650f9c091ef71cb01d735775d554e068752d3ff63d7943b26316dc401749/numpy-1.21.2.zip (10.3MB)
100% |████████████████████████████████| 10.3MB 163kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-1swfqubc/numpy/setup.py", line 34, in <module>
raise RuntimeError("Python version >= 3.7 required.")
RuntimeError: Python version >= 3.7 required.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-1swfqubc/numpy/
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
czl@czl-RedmiBook-14:~$
失败!TF和CUDA以及anaconda的关系比较复杂,后面有空再研究.