Meet Anaconda for the first time

 

Meet Anaconda for the first time

        Anaconda, the leading open data science platform powered by Python, is a package manager and environment manager, and Jupyter notebook can combine data analysis code, images and documentation all into a single web document; its open source versions are Python and R A high-performance distribution of over 100 of the most popular Python, R, and Scala packages for data science.

download

Installing Python 3.6 succeeded, but I seem to be doing redundant things after hearing that Anaconda has Python pre-installed. It doesn't matter, Quan Ji regarded it as a long-term experience... Downloading Anaconda is not smooth. It has been operated on the official website 6 times, and after 8 hours, the download failed. Finally, according to the notes of (Time Star Shower: https://blog.csdn.net/qq_36790747/article/details/63257244) , the installation was smooth, and the speed was indeed at least 5 times faster.

  Download Anaconda installation package from Tsinghua Mirror: Tsinghua Open Source Mirror (recommended)

Install

1. Whether to add Anaconda to the environment variable, which involves whether you can use conda, jupyter, ipython and other commands directly in cmd, it is recommended to tick. When installing, you need to check to my PATH environment

 

2. If the environment variable is not set properly for some reason, the later rescue plan for Windows to set the environment variable - manually add the Python directory to the environment variable:

       1) In the command prompt box (cmd): Enter path=%path%;C:\Python and press "Enter", where: C:\Python is the Python installation directory.

       2) Right-click "Computer"--"Properties"--Advanced System Settings--Environment Variables--System Variables--Select Path, Edit--Add Installation Path, (if "Edit Text", the path is directly used A semicolon ";" separates the other paths before it --- ";D:\Python 3.6")

    

 

      3) After the setting is successful, in the cmd command line, enter the command "python", you can have the relevant display.

3. Check the results of labor:

      1) Run the start menu -> Anaconda3 -> Anaconda Prompt:  conda-version

      2) There may be no permission, the reason is that the win10 system needs to open the software as an administrator. (Monkey's text: https://www.zhihu.com/question/58033789/answer/254673663)

      3) If the conda command can be used in Anaconda Prompt, then continue the operation below.

      4) In order to avoid errors in later use, you need to update all packages first. Enter the command to update all packages in the terminal: conda update --all     When prompted whether to update, enter y (Yes).

      5)另外,'upgrade\xa0\xa0\xa0' (choose from 'clean', 'config', 'create', 'help', 'info', 'install', 'list', 'package', 'remove', 'uninstall', 'search', 'update', 'upgrade'

     

Configuration Environment

The Tsinghua TUNA mirror source has the Anaconda warehouse mirror address, and we add it to the conda configuration.

Please run the following code in cmd: or (run start menu->Anaconda3->Anaconda Prompt)

1)   conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/  

2)  conda config --set show_channel_urls yes   

3) # Set the channel address to display when searching

Python environment management

conda can create different runtime environments for your different projects. 

1) Create an environment

Use in terminal: conda create -n env_name package_names

In the above command, env_name is the name of the setting environment (-n means that the env_name after the command is the name of the environment you want to create), and package_names is the name of the package you want to install in the created environment.

例如,要创建环境名称为 py3 的环境并在其中安装 pandas,在终端中输入 conda create -n py3 pandas

2)创建环境时,可以指定要安装在环境中的 Python 版本

当你同时使用 Python 2.x 和 Python 3.x 中的代码时这很有用。要创建具有特定 Python 版本的环境,例如创建环境名称为py3,并安装最新版本的Python3在终端中输入:conda create -n py3 python=3

或也可以这样创建环境名称为py2,并安装最新版本的Python2:conda create -n py2 python=2

3)我们现在安装的是最新版Anaconda3,其自带的Python版本为3.6,如果我们需要添加2.7版本的Python,可以进行如下操作。(同理,如果要添加Python 3.x,之后操作里的2.7改为3.6或3.5即可)

conda create -n py27 python=2.7 

4)共享环境(还不会操作)

a. 你可以在你当前的环境终端中使用 conda env export > environment.yaml 将你当前的环境保存到文件中包保存为YAML文件(包括Pyhton版本和所有包的名称)。

b. 命令的第一部分 conda env export 用于输出环境中的所有包的名称(包括 Python 版本)。

c. 在“notebook工作文件夹”下(及你在终端中上图的路径)可以看到导出的环境文件:

在 GitHub 上共享代码时,最好同样创建环境文件并将其包括在代码库中。这能让其他人更轻松地安装你的代码的所有依赖项。

导出的环境文件,在其他电脑环境中如何使用呢?

d. 首先在conda中进入你的环境,比如activate py3

e. 然后在使用以下命令更新你的环境:其中-f表示你要导出文件在本地的路径,所以/path/to/environment.yml要换成你本地的实际路径:conda env update -f=/path/to/environment.yml

f. 对于不使用 conda 的用户,通常还可使用 pip freeze > environment.txt 将一个 txt文件导出并包括在其中。

举例:

首先,我在自己的电脑上在conda中将项目的包导出成environment.txt 文件;然后我将该文件包含在项目的代码库中,其他项目成员即使在他的电脑上没有安装conda也可以使用该文件来安装和我一样的开发环境;他在自己的电脑上进入python命令环境,然后运行以下命令就可以安装该项目需要的包:(其中/path/requirements.txt是该文件在你电脑上的实际路径)pip install -r /path/requirements.txt

5)激活环境:通过activate py3命令
6)退出环境:通过deactivate py3。
7)列出环境:用 conda env list 就可以列出你创建的所有环境(或通过conda info -e命令查看已有的环境)。当前所在环境的旁边会有一个星号。默认的环境(即当你不在选定环境中时使用的环境)名为 root。

8)删除环境:通过conda remove -n env_name –all来删除指定的环境(如果不添–all参数,而是指明某个库名,则是删除该库;在这里环境名为 env_name)。

9)  TensorFlow环境在windows上安装与简单示例 (参考叶晚林的文:https://blog.csdn.net/darlingwood2013/article/details/60322258)

      1.检测目前安装了哪些环境:conda info --envs

      2.检查目前有哪些版本的python可以安装:conda search --full-name python

      3.安装版本3.6的python:conda create --name tensorflow python=3.6   (tensorflow环境中安装了python=3.6)

      5.按照提示,激活之:activate tensorflow

      6.确保名叫tensorflow的环境(与py3的环境类似)已经被成功添加:conda info --envs

      7.检查新环境中的python版本:python --version

      8.退出当前环境:deactivate

      9.切换环境:activate py3

      10、还可以点开Anaconda Navigator查看已配置的环境和安装的包。

如何管理包

安装了 Anaconda 之后,就可以很方便的管理包了(安装,卸载,更新)。

1  安装包

在Anaconda Prompt中键入:conda install package_name

例如,要安装 pandas,在终端中输入:conda install pandas

你还可以同时安装多个包。类似conda install pandas numpy的命令会同时安装所有这些包。还可以通过添加版本号(例如conda install numpy=1.10)来指定所需的包版本。

conda 还会自动为你安装依赖项。例如,scipy 依赖于 numpy,因为它使用并需要 numpy。如果你只安装 scipy (conda install scipy),则 conda 还会安装 numpy(如果尚未安装的话)。

2  卸载包

在终端中键入conda remove package_names

上面命令中的package_names是指你要卸载包的名称,例如你想卸载pandas包:conda remove pandas

3  更新包

在终端中键入:conda update package_name

如果想更新环境中的所有包(这样做常常很有用),使用:conda update --all

4  搜索包:不知道要找的包的确切名称,可以尝试使用conda search search_term 进行搜索。例如,我知道我想安装numpy,但我不清楚确切的包名称。我可以这样尝试:conda search num

 

Python的基础知识

1  变量的定义

1). 变量名只能是 字母、数字或下划线的任意组合

2). 变量名的第一个字符不能是数字

3). 关键字不能声明为变量名['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']

 

2  文字格式

1)驼峰体

AgeOfOldboy = 56

NumberOfStudents = 80

2)下划线(推荐使用)

age_of_oldboy = 56

number_of_students = 80

                 3)常量

程序员约定俗成用变量名全部大写代表常量

AGE_OF_OLDBOY = 56

 

3  注释使用“#”,增加代码的可读性。

1)代码注释分单行和多行注释, 单行注释用#,多行注释可以用三对双引号""" """

 2)代码注释的原则:

#1. 不用全部加注释,只需要在自己觉得重要或不好理解的部分加注释即可

#2. 注释可以用中文或英文,但不要用拼音 

 

4  文件头(中文的引入)

#!/usr/bin/env python

# -*- coding: utf-8 -*-

 

5  第一个python程序

#进入解释器的交互式模式:调试方便,无法永久保存代码
#脚本文件的方式(使用nodpad++演示):永久保存代码
强调:python解释器执行程序是解释执行,即打开文件读内容,因此文件的后缀名没有硬性限制,但通常定义为.py结尾

 全文参考:1   https://blog.csdn.net/qq_36790747/article/details/63257244

                   2   https://www.zhihu.com/question/22112542/answer/166053516

                   3   https://www.zhihu.com/question/58033789/answer/254673663

                   4   https://blog.csdn.net/darlingwood2013/article/details/60322258

 

人生第一篇博客

 2018.5.4  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325345244&siteId=291194637