Python之路【第一篇】:使用miniconda安装python多版本

2021-05-16 12:27

阅读:693

标签:require   perm   www   mirror   trie   rom   object   color   services   

一、简介

Anaconda是一个发行包,里面集成打包了很多的软件包,使用conda包管理器来安装软件,比较方便,但是Anaconda软件包太大,个人不太喜欢,想自己定制。Miniconda中只有Conda包管理器,正是我想要的,下面简单介绍一下Miniconda的简单配置方法。

二、配置使用

1. 下载软件包:

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.3.14-Linux-x86_64.sh
 

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  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  [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 to a verbose appending log.
  --proxy              Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries          Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout              Set the socket timeout (default 15 seconds).
  --exists-action     Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).
  --trusted-host    Mark this host as trusted, even though it does
                              not have valid or any HTTPS.
  --cert                Path to alternate CA bundle.
  --client-cert         Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir            Store the cache data in .
  --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
 

Python之路【第一篇】:使用miniconda安装python多版本

标签:require   perm   www   mirror   trie   rom   object   color   services   

原文地址:https://www.cnblogs.com/gaoqinglong/p/9748962.html


评论


亲,登录后才可以留言!