一、簡介
Anaconda是一個發行包,里面集成打包了很多的軟件包,使用conda包管理器來安裝軟件,比較方便,但是Anaconda軟件包太大,個人不太喜歡,想自己定制。Miniconda中只有Conda包管理器,正是我想要的,下面簡單介紹一下Miniconda的簡單配置方法。
二、配置使用
1. 下載軟件包:
2. 安裝:
bash Miniconda3-4.3.14-Linux-x86_64.sh
####顯示過程####:
Welcome to Miniconda3 4.3.14 (by Continuum Analytics, Inc.) In order to continue the installation process, please review the license agreement. Please, press ENTER to continue >>> # 按回車,之后按空格鍵顯示完全license信息 ================= Miniconda 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. 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.). Do you approve the license terms? [yes|no] >>> yes # 同意license條款 Miniconda3 will now be installed into this location: /home/gql/miniconda3 - Press ENTER to confirm the location - Press CTRL-C to abort the installation - Or specify a different location below [/home/gql/miniconda3] >>> # 此處可修改到其他目錄,也可以默認 PREFIX=/home/gql/miniconda3 installing: python-3.6.0-0 ... installing: cffi-1.9.1-py36_0 ... installing: conda-env-2.6.0-0 ... installing: cryptography-1.7.1-py36_0 ... installing: idna-2.2-py36_0 ... installing: libffi-3.2.1-1 ... installing: openssl-1.0.2k-1 ... installing: pyasn1-0.1.9-py36_0 ... installing: pycosat-0.6.1-py36_1 ... installing: pycparser-2.17-py36_0 ... installing: pyopenssl-16.2.0-py36_0 ... installing: readline-6.2-2 ... installing: requests-2.12.4-py36_0 ... installing: ruamel_yaml-0.11.14-py36_1 ... installing: setuptools-27.2.0-py36_0 ... installing: six-1.10.0-py36_0 ... installing: sqlite-3.13.0-0 ... installing: tk-8.5.18-0 ... installing: xz-5.2.2-1 ... installing: yaml-0.1.6-0 ... installing: zlib-1.2.8-3 ... installing: conda-4.3.14-py36_0 ... installing: pip-9.0.1-py36_1 ... installing: wheel-0.29.0-py36_0 ... Python 3.6.0 :: Continuum Analytics, Inc. creating default environment... installation finished. Do you wish the installer to prepend the Miniconda3 install location to PATH in your /home/gql/.bashrc ? [yes|no] [no] >>> yes # 同意把conda添加到用戶環境變量中 Prepending PATH=/home/gql/miniconda3/bin to PATH in /home/gql/.bashrc A backup will be made to: /home/gql/.bashrc-miniconda3.bak For this change to become active, you have to open a new terminal. Thank you for installing Miniconda3! Share your notebooks and packages on Anaconda Cloud! Sign up for free: https://anaconda.org
####安裝完成######
3. 查看並使得conda命令生效(windows不用)
(1)查看:
tail -3 ~/.bashrc
若顯示如下,則表示命令已經添加到用戶環境變量中:
# added by Miniconda3 4.3.14 installer
export PATH="/home/gql/miniconda3/bin:$PATH"
(2)使生效
source ~/.bashrc # .bashrc文件生效
4. 更換conda源和pip源:
(1)conda源:(使用清華開源鏡像站的源)
編寫配置文件:
vim ~/.condarc # 新建配置文件並打開
若windows:
C:\Users\用戶名\.condarc
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - defaults show_channel_urls: true
英文輸入法條件下,按i進入輸入模式,把上述配置拷貝進去即可。
輸入完之后,按esc鍵,然后按 :x 保存並退出。
(2)pip源:(使用清華開源鏡像站的源)
mkdir ~/.pip # 在用戶家目錄下創建.pip 隱藏文件夾
vim ~/.pip/pip.conf # 新建配置文件並打開
若windows:
C:\Users\用戶名\pip\pip.ini
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
或豆瓣源:
[global] trusted-host = pypi.douban.com index-url = http://pypi.douban.com/simple
5. 創建python任意版本虛擬環境:
比如:python2.7
conda create --name py2 python=2.7
查看當前conda管理的虛擬環境有哪些:
conda info --envs
6. 修改進入虛擬環境的命令(windows不用)
vim ~/.bashrc # 在文件的最下面添加下面兩行,不是必須(個人喜好 ^_^)
alias workon='source activate'
alias pybye='source deactivate'
修改環境變量之后使生效:
source ~/.bashrc
此時進入虛擬環境的命令:
workon py2
離開虛擬環境的命令:
pybye
7. 進入虛擬環境安裝軟件包:
workon py2 # 進入虛擬環境,或 source activate py2 / windows:activate py2
pip install 軟件包名 # 安裝軟件包
附加常用命令:
pip list # 查看當前虛擬環境存在的軟件包
pip freeze # 查看當前虛擬環境存在的軟件包,同時顯示處具體版本
比如在某個相同環境軟件包重定向到文件:pip freeze > py2.txt
再使用相同環境的文件安裝軟件包:pip install -r py2.txt
pip的所有命令:
Usage: pip <command> [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. config Manage local and global configuration. search Search PyPI for packages. wheel Build wheels from your requirements. hash Compute hashes of package archives. completion A helper command used for command completion. help Show help for commands. General Options: -h, --help Show help. --isolated Run pip in an isolated mode, ignoring environment variables and user configuration. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels). --log <path> Path to a verbose appending log. --proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port. --retries <retries> Maximum number of retries each connection should attempt (default 5 times). --timeout <sec> Set the socket timeout (default 15 seconds). --exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort). --trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS. --cert <path> Path to alternate CA bundle. --client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format. --cache-dir <dir> Store the cache data in <dir>. --no-cache-dir Disable the cache. --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index. --no-color Suppress colored output
Ps: 若沒有配置,命令行使用其他源安裝:
pip install numpy.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com