Python笔记 #05# Package & pip3
datacamp + 日常收集
pip3 & What is difference between pip and pip3?
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的更多相关文章
- python笔记05
python笔记05 数据类型 上个笔记知识点总结: 列表中extend特性:extend,(内部循环,将另外一个列表,字符串.元组添加到extend前的列表中) li.extend(s),将s中元素 ...
- 我的python笔记05
Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve ...
- python笔记05:条件、循环和其它语句
5.1 print和import的更多使用方式 5.1.1 使用逗号输出 print 'Age',42 print 1,2,3 如果要同时输出文本和变量值,又不希望使用字符串格式化的话,那么这个特性就 ...
- python笔记-1(import导入、time/datetime/random/os/sys模块)
python笔记-6(import导入.time/datetime/random/os/sys模块) 一.了解模块导入的基本知识 此部分此处不展开细说import导入,仅写几个点目前的认知即可.其 ...
- python笔记 - day5
python笔记 - day5 参考: http://www.cnblogs.com/wupeiqi/articles/5484747.html http://www.cnblogs.com/alex ...
- python笔记之常用模块用法分析
python笔记之常用模块用法分析 内置模块(不用import就可以直接使用) 常用内置函数 help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像 ...
- python笔记之提取网页中的超链接
python笔记之提取网页中的超链接 对于提取网页中的超链接,先把网页内容读取出来,然后用beautifulsoup来解析是比较方便的.但是我发现一个问题,如果直接提取a标签的href,就会包含jav ...
- 机器学习实战(Machine Learning in Action)学习笔记————05.Logistic回归
机器学习实战(Machine Learning in Action)学习笔记————05.Logistic回归 关键字:Logistic回归.python.源码解析.测试作者:米仓山下时间:2018- ...
- python笔记24-unittest单元测试之mock.patch
前言 上一篇python笔记23-unittest单元测试之mock对mock已经有初步的认识, 本篇继续介绍mock里面另一种实现方式,patch装饰器的使用,patch() 作为函数装饰器,为您创 ...
随机推荐
- 说说SPI协议
SPI,是英语Serial Peripheral Interface 的缩写,顾名思义就是串行外围设备接口.SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用四根线,节约了芯片的管 ...
- 【PHP】php 生成条形码
1.什么是条形码? 百度百科定义:条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常见的条形码是由反射率相差很大的黑条(简称条)和白条(简称 ...
- MQTT协议笔记之mqtt.io项目TCP协议支持
前言 MQTT定义了物联网传输协议,其标准倾向于原始TCP实现.构建于TCP的上层协议堆栈,诸如HTTP等,在空间上多了一些处理路径,稍微耗费了CPU和内存,虽看似微乎其微,但对很多处理能力不足的嵌入 ...
- VScode之JavaScript Snippet Pack
一个片段包 使用例如: cl 回车或者tab键,就可以完整的打出console.log("") 还有很多快捷功能: 参考: https://marketplace.visualst ...
- 自行颁发不受浏览器信任的SSL证书
ssh登陆到服务器上,终端输入以下命令,使用openssl生成RSA密钥及证书. # 生成一个RSA密钥 $ openssl genrsa -des3 -out 33iq.key 1024 # 拷贝一 ...
- Xshell配置ssh免密码登录-密钥公钥(Public key)
1 简介 ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,这里介绍密钥认证方式登录到linux/unix的方法. 使用密钥登录分为3步: 1 ...
- Linux登录失败处理功能
本文要实现的功能:如果有人恶意尝试破解你的服务器密码,那么这个功能就能帮你起到一定的作用,当尝试密码错误超过设定的次数后,就会锁定该账户多长时间(自行设定),时间过后即可自行解锁,这样可以增加攻击者 ...
- sqlserver字符串多行合并为一行
--创建测试表 CREATE TABLE [dbo].[TestRows2Columns]( [Id] [,) NOT NULL, [UserName] [nvarchar]() NULL, [Sub ...
- Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure stylesheet 非全站https
Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure ...
- the source attachment does not contain the source for the file xxx.class无法关联到某个类
问题描述: 按下列操作添加相应路径(这里是错误操作) 该问题仍旧无法解决: 注意:这里spring-webmvc-4.1.7.RELEASE.JAR中确实包含AnntationMethodHandle ...