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() 作为函数装饰器,为您创 ...
随机推荐
- iOS 录音功能的实现
这两天也调了一下ios的录音,原文链接:http://www.iphoneam.com/blog/index.php?title=using-the-iphone-to-record-audio-a- ...
- iOS设计模式之类族(class cluster)
类族模式在UIKit(user interface framework)使用的范围已经远远超过我们的想象,比如,UIButton,NSArray,NSString,NSNumber等, 例如NSNum ...
- linux mysql添加用户,删除用户,以及用户权限
一些主要的命令: 登录: mysql -u username -p 显示全部的数据库: show databases; 使用某一个数据库: use databasename; 显示一个数据库的全部表: ...
- Excel 2010版筛选怎么用
很多人在使用excel表格的时候,不知道这个筛选功能怎么用,可以对我们平时做数据和表格带来哪些帮助.那么,接下来,小敏以excel表格2010版为例,跟大家分享一下这个excel表格筛选功能的使用方法 ...
- mysql 效率 inner join 与 where in
-- report 123.77k行 report_loss 620 行 -- inner join ;report_loss 索引 all report 索引 eq_ref ; -- total 0 ...
- 【BZOJ4774/4006】修路/[JLOI2015]管道连接 斯坦纳树
[BZOJ4774]修路 Description 村子间的小路年久失修,为了保障村子之间的往来,法珞决定带领大家修路.对于边带权的无向图 G = (V, E),请选择一些边,使得1 <= i & ...
- angular -- post请求该如何使用?
angularjs 的post 请求该如何调用? 简单示例: // post 携带参数访问 $http({ method:'post', url:postUrl, data:{name:"a ...
- JAVA内存构成详解
java memory = direct memory(直接内存) + jvm memory(MaxPermSize +Xmx) 1)直接内存跟堆 直接内存则是一块由程序本身管理的一块内存空间,它 ...
- python中super的使用
转自:http://python.jobbole.com/86787/ super() 的入门使用 在类的继承中,如果重定义某个方法,该方法会覆盖父类的同名方法,但有时,我们希望能同时实现父类的功能, ...
- 过山车---hdu2063(最大匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063最大匹配模板题: #include <iostream> #include <c ...