datacamp + 日常收集

How to install Package

pip3 & What is difference between pip and pip3?

Import  Package

Selective import

Different ways of importing

How to install Package

在 Python 中,我们通常使用 pip 来安装 Package(扩展包)。pip 是 python 的一个包管理工具(类似于各种 Linux distribution 里的包管理工具)。

步骤是这样的,首先需要先到 pip 的官网(google 一下)下载 get-pip.py ,之后打开终端运行 get-pip.py “真正”地安装它,然后就可以轻松地使用 pip 命令来安装各种扩展包。

What is difference between pip and pip3?

pip3 always operates on the Python3 environment only, as pip2 does with Python2. pip operates on whichever environment is appropriate to the context. For example if you are in a Python3 venv, pip will operate on the Python3 environment. -- Brendan Donegan, Automating testing using Python for 6 years

Import Package

当我们安装好扩展包后,如何在代码中使用它呢?主要有以下几种方式:

1)

2)

3)

用哪种全凭喜好,不过我比较倾向于用方式一。范例代码:

# Definition of radius
r = 0.43 # Import the math package
import math # Calculate C
C = 2 * math.pi * r # Calculate A
A = math.pi * r ** 2 # Build printout
print("Circumference: " + str(C))
print("Area: " + str(A))

Selective import

# Definition of radius
r = 192500 # Import radians function of math package
from math import radians # Travel distance of Moon over 12 degrees. Store in dist.
dist = r * radians(12) # Print out dist
print(dist)

Different ways of importing

There are several ways to import packages and modules into Python. Depending on the import call, you'll have to use different Python code.

Suppose you want to use the function inv(), which is in the linalgsubpackage of the scipy package. You want to be able to use this function as follows:

my_inv([[1,2], [3,4]])

Which import statement will you need in order to run the above code without an error?

from scipy.linalg import inv as my_inv

Python笔记 #05# Package & pip3的更多相关文章

  1. python笔记05

    python笔记05 数据类型 上个笔记知识点总结: 列表中extend特性:extend,(内部循环,将另外一个列表,字符串.元组添加到extend前的列表中) li.extend(s),将s中元素 ...

  2. 我的python笔记05

    Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve ...

  3. python笔记05:条件、循环和其它语句

    5.1 print和import的更多使用方式 5.1.1 使用逗号输出 print 'Age',42 print 1,2,3 如果要同时输出文本和变量值,又不希望使用字符串格式化的话,那么这个特性就 ...

  4. python笔记-1(import导入、time/datetime/random/os/sys模块)

    python笔记-6(import导入.time/datetime/random/os/sys模块)   一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...

  5. python笔记 - day5

    python笔记 - day5 参考: http://www.cnblogs.com/wupeiqi/articles/5484747.html http://www.cnblogs.com/alex ...

  6. python笔记之常用模块用法分析

    python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...

  7. python笔记之提取网页中的超链接

    python笔记之提取网页中的超链接 对于提取网页中的超链接,先把网页内容读取出来,然后用beautifulsoup来解析是比较方便的.但是我发现一个问题,如果直接提取a标签的href,就会包含jav ...

  8. 机器学习实战(Machine Learning in Action)学习笔记————05.Logistic回归

    机器学习实战(Machine Learning in Action)学习笔记————05.Logistic回归 关键字:Logistic回归.python.源码解析.测试作者:米仓山下时间:2018- ...

  9. python笔记24-unittest单元测试之mock.patch

    前言 上一篇python笔记23-unittest单元测试之mock对mock已经有初步的认识, 本篇继续介绍mock里面另一种实现方式,patch装饰器的使用,patch() 作为函数装饰器,为您创 ...

随机推荐

  1. Linux 文件基本属性(转)

    Linux 文件基本属性 Linux系统是一种典型的多用户系统,不同的用户处于不同的地位,拥有不同的权限.为了保护系统的安全性,Linux系统对不同的用户访问同一文件(包括目录文件)的权限做了不同的规 ...

  2. 使用NSTimer实现动画

    1.新建empty AppLication,添加HomeViewController页面, iphone.png图片 2.在 HomeViewController.xib中添加Image View,并 ...

  3. 【TP3.2】 动态切换数据库方法

    1 config 配置: 'connection' => 'mysql://root:root@localhost:3306/dbname', connection  数据库连接字符串,后面代码 ...

  4. POJ3259-负权回路判定

    题目:http://vj.acmclub.cn/contest/view.action?cid=316#problem/E 首先要理解题意:其实就是给你一个图让你判断有没有负权回路 因此直接用Ball ...

  5. 用Iterator实现遍历集合

    使用Collection类的Iterator,可以方便的遍历Vector, ArrayList, LinkedList等集合元素,避免通过get()方法遍历时,针对每一种对象单独进行编码. 示例: C ...

  6. CSS 3D的应用记录

    为父元素添加以下样式后,子元素即可使用3D属性,例如translateZ /*设置子元素也应用3D效果*/-webkit-transform-style: preserve-3d;-moz-trans ...

  7. fastcgi_param解释

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径 fastcgi_param QUERY_STRI ...

  8. java - OutOfMemoryError: Java heap space 堆空间不足

    Error occurred during initialization of VM Could not reserve enough space for object heap Error: Cou ...

  9. 【BZOJ3727】PA2014 Final Zadanie 树形DP

    [BZOJ3727]PA2014 Final Zadanie Description 吉丽YY了一道神题,题面是这样的:“一棵n个点的树,每条边长度为1,第i个结点居住着a[i]个人.假设在i结点举行 ...

  10. ios 去除UITextField中的空格

    NSString *qName =[userNameText.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNew ...