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 linalg
subpackage 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() 作为函数装饰器,为您创 ...
随机推荐
- 说说FATFS文件系统(转)
FATFS是一个为小型嵌入式系统设计的通用FAT(File Allocation Table)文件系统模块.FatFs 的编写遵循ANSI C,并且完全与磁盘I/O层分开.因此,它独立(不依赖)于硬件 ...
- web基础----->readonly与disabled的区别
readonly和Disabled是用在表单中的两个属性,它们都能够做到使用户不能够更改表单域中的内容.但是它们之间有着微小的差别,今天我们通过案例来学习一下. readonly和Disabled的区 ...
- jQuery的无new构建
正常面向对象的写法: var cJquery = function(){ //构造函数体 }; cJquery.prototype = { name : function(alert("ch ...
- 【BZOJ1045】[HAOI2008] 糖果传递 贪心
[BZOJ1045][HAOI2008] 糖果传递 Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. Input 第一行一个正 ...
- python随机验证码函数
#验证码函数def yzm(i): code = [] for i in range(i): ,): code.append(str(random.randint(,))) else: tmp = r ...
- centos7安装mysql(MariaDB)
1.centos7现状: 新系统无法再使用yum install mysql-server来安装mysql,因为已使用mariadb代替mysql. 2.安装mariadb: [root@localh ...
- onethink重新安装,提示已安装过解决办法!
onethink完全重新安装的时候提示已安装过,直接跳过数据库安装的解决办法 首先:删除根目录下 Data目录下的 install.lock 文件,然后: 打开\Application\Install ...
- 学习c++的50条忠告(转自C++百度贴吧)
1.把C++当成一门新的语言学习(和C没啥关系!真的.): 2.看<Thinking In C++>,不要看<C++变成死相>: 3.看<The C++ Programm ...
- Jmeter性能测试实践之java请求
前言 Apache Jmeter是开源.易用的性能测试工具,之前工作中用过几次对http请求进行性能测试,对jmeter的基本操作有一些了解.最近接到开发的对java请求进行性能测试的需求,所以需要 ...
- postgresql----数据库表约束----NOT NULL,DEFAULT,CHECK
数据库表有NOT NULL,DEFAULT,CHECK,UNIQUE,PRIMARY KEY,FOREIGN KEY六种约束. 一.NOT NULL ---- 非空约束 NULL表示没有数据,不表示具 ...