先看教程: https://docs.xinzhiba.top/python/3.10/tutorial/index.html 然后看标准库: https://docs.xinzhiba.top/python/3.10/library/index.html
对象类型 | 用途 | 示例 |
---|---|---|
Strings 字符串 | ||
Lists 列表 | ||
Dictionary 字典 | ||
Files 文件操作 | ||
Logging 日志操作类库 | ||
sqlite3 库支持 | ||
PyMongo | Mongodb connect driver | |
OpenCV 计算机视觉(Computer Vision) | image processing, machine learning | |
Pillow | image processing | 读取图片信息、旋转、翻转、调整亮度、对比度等 |
Numpy | NumPy(Numerical Python) 是 Python 语言的一个扩展程序库,支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。 | |
Pandas 数据分析execl | Pandas 库是一个免费、开源的第三方 Python 库,是 Python 数据分析必不可少的工具之一,它为 Python 数据分析提供了高性能,且易于使用的数据结构,即 Series 和 DataFrame。Pandas 自诞生后被应用于众多的领域,比如金融、统计学、社会科学、建筑工程等。 |
1>>> print(r'fsadfjk"fasdf"fads')
2fsadfjk"fasdf"fads
CPython
是一个可以执行你写的python代码的另一个由 C 语言写的程序。,类似的还有PyPy(使用python实现的python)/Jython(使用java实现的python),.NET(C#)实现的叫IronPython
学习Python不止要学习Python本身,你还要学习很多第三方库,比如matlab五件套scipy,numpy,pandas,sympy,matplotlib。机器学习框架库:pytorch,tensorflow
xxxxxxxxxx
321PS D:\kava\python> pip install numpy
2Collecting numpy
3 Downloading numpy-1.22.3-cp310-cp310-win_amd64.whl (14.7 MB)
4 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.7/14.7 MB 415.7 kB/s eta 0:00:00
5Installing collected packages: numpy
6Successfully installed numpy-1.22.3
7WARNING: You are using pip version 22.0.4; however, version 22.1 is available.
8You should consider upgrading via the 'C:\Users\Amos\AppData\Local\Programs\Python\Python310\python.exe -m pip install --upgrade pip' command.
9PS D:\kava\python> C:\Users\Amos\AppData\Local\Programs\Python\Python310\python.exe -m pip install --upgrade pip'
10>> ^C
11PS D:\kava\python> py
12Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
13Type "help", "copyright", "credits" or "license" for more information.
14>>> exit
15Use exit() or Ctrl-Z plus Return to exit
16>>> exit
17Use exit() or Ctrl-Z plus Return to exit
18>>> exit
19Use exit() or Ctrl-Z plus Return to exit
20>>> exit()
21PS D:\kava\python> py -m pip install --upgrade pip
22Requirement already satisfied: pip in c:\users\amos\appdata\local\programs\python\python310\lib\site-packages (22.0.4)
23Collecting pip
24 Downloading pip-22.1-py3-none-any.whl (2.1 MB)
25 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 3.5 MB/s eta 0:00:00
26Installing collected packages: pip
27 Attempting uninstall: pip
28 Found existing installation: pip 22.0.4
29 Uninstalling pip-22.0.4:
30 Successfully uninstalled pip-22.0.4
31Successfully installed pip-22.1
32PS D:\kava\python>
python 标准库位置: %python安装路径%\Lib
x1# 进入python IDE环境,执行如下命令可以查看基础库列表
2
3PS F:\Users\Amos\Desktop> python
4Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
5Type "help", "copyright", "credits" or "license" for more information.
6>>> help('modules')
7
8Please wait a moment while I gather a list of all available modules...
9__future__ _threading_local gettext sched
10_abc _tkinter glob secrets
11_aix_support _tracemalloc graphlib select
12_ast _uuid gzip selectors
13_asyncio _warnings hashlib setuptools
14_bisect _weakref heapq shelve
15_blake2 _weakrefset hmac shlex
16_bootsubprocess _winapi html shutil
17_bz2 _xxsubinterpreters http signal
18_codecs _zoneinfo idlelib site
19_codecs_cn abc idlexlib smtpd
20_codecs_hk aifc imaplib smtplib
21_codecs_iso2022 antigravity imghdr sndhdr
22_codecs_jp argparse imp socket
23_codecs_kr array importlib socketserver
24_codecs_tw ast inspect sqlite3
25_collections asynchat io sre_compile
26_collections_abc asyncio ipaddress sre_constants
27_compat_pickle asyncore itertools sre_parse
28_compression atexit json ssl
29_contextvars audioop keyword stat
30_csv base64 lib2to3 statistics
31_ctypes bdb linecache string
32_ctypes_test binascii locale stringprep
33_datetime binhex logging struct
34_decimal bisect lzma subprocess
35_distutils_hack builtins mailbox sunau
36_elementtree bz2 mailcap symtable
37_functools cProfile marshal sys
38_hashlib calendar math sysconfig
39_heapq cgi mimetypes tabnanny
40_imp cgitb mmap tarfile
41_io chunk modulefinder telnetlib
42_json cmath msilib tempfile
43_locale cmd msvcrt test
44_lsprof code multiprocessing textwrap
45_lzma codecs netrc this
46_markupbase codeop nntplib threading
47_md5 collections nt time
48_msi colorsys ntpath timeit
49_multibytecodec compileall nturl2path tkinter
50_multiprocessing concurrent numbers token
51_opcode configparser numpy tokenize
52_operator contextlib opcode trace
53_osx_support contextvars operator traceback
54_overlapped copy optparse tracemalloc
55_pickle copyreg os tty
56_py_abc crypt pathlib turtle
57_pydecimal csv pdb turtledemo
58_pyio ctypes pickle types
59_queue curses pickletools typing
60_random dataclasses pip unicodedata
61_sha1 datetime pipes unittest
62_sha256 dbm pkg_resources urllib
63_sha3 decimal pkgutil uu
64_sha512 difflib platform uuid
65_signal dis plistlib venv
66_sitebuiltins distutils poplib warnings
67_socket doctest posixpath wave
68_sqlite3 email pprint weakref
69_sre encodings profile webbrowser
70_ssl ensurepip pstats winreg
71_stat enum pty winsound
72_statistics errno py_compile wsgiref
73_string faulthandler pyclbr xdrlib
74_strptime filecmp pydoc xml
75_struct fileinput pydoc_data xmlrpc
76_symtable fnmatch pyexpat xxsubtype
77_testbuffer fractions queue zipapp
78_testcapi ftplib quopri zipfile
79_testconsole functools random zipimport
80_testimportmultiple gc re zlib
81_testinternalcapi genericpath reprlib zoneinfo
82_testmultiphase getopt rlcompleter
83_thread getpass runpy
84
85Enter any module name to get more help. Or, type "modules spam" to search
86for modules whose name or summary contain the string "spam".
87
88>>>
89>>>
90>>>
python 第三方库位置: %python安装路径%\Lib\site-packages
xxxxxxxxxx
121# 查看已安装的第3方扩展库列表及版本
2pip list
3或
4pip freeze
5
6# 验证第3方库是否安装,已安装时无信息输出
7
8>>> import matplotlib
9Traceback (most recent call last):
10 File "<stdin>", line 1, in <module>
11ModuleNotFoundError: No module named 'matplotlib'
12>>>
pip命令实例 说明 pip freeze 列出已安装模块及其版本号 pip install package[==version] 在线安装指定模块(的指定版本) pip install package.whl 离线安装扩展模块 pip install package1 package2 依次在线安装模块1、模块2 pip install --upgrade package 升级模块 pip uninstall package[==version] 卸载模块
参考: https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
或者直接使用
http://mirrors.aliyun.com/pypi/simple/
https://repo.huaweicloud.com/repository/pypi/simple/
国内镜像 https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/ 直接下载最新版安装包,页面说明。
类库分类:解析库、工具库、存储库
xxxxxxxxxx
151C:\Users\Amos>where python
2
3C:\Users\Amos\AppData\Local\Programs\Python\Python310\python.exe
4C:\Users\Amos\AppData\Local\Microsoft\WindowsApps\python.exe
5C:\Program Files\Inkscape\bin\python.exe
6
7C:\Users\Amos>
8
9## 查看路径
10C:\Users\Amos>pip -V
11pip 22.1 from C:\Users\Amos\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)
12
13C:\Users\Amos>pip3 -V
14pip 22.1 from C:\Users\Amos\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)
15
处理方式1:
创建新的可执行文件的别名或复本,原先的保留不动
处理方式2:
在环境变量中调整PATH变量中的路径先后顺序,即能实现调整优先级,在前面的优先加载和调用。
处理方式3: 高级virtualenv
pycharm支持调用或创建virtualenv
https://pypi.org/project/virtualenvwrapper/
https://zhuanlan.zhihu.com/p/82559341
xxxxxxxxxx
61pip install virtualenv
2pip3 install virtualenv
3
4pip install virtualenvwrapper
5pip install virtualenvwrapper-win #Windows使用该命令
6
类库分类:解析库、工具库、存储库
为默认集成的官方库。
通过pip 安装
弹出一个浏览器窗口。
pip install selenium
其使用时依赖:chromedriver(6MB),其仅是一个可执行程序,将其放置到环境变量目录下即可,下载:
https://chromedriver.chromium.org/ 或https://chromedriver.chromium.org/downloads
https://chromedriver.storage.googleapis.com/index.html?path=102.0.5005.27/
Selenium是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome,Opera,Edge等。这个工具的主要功能包括:测试与浏览器的兼容性——测试应用程序看是否能够很好得工作在不同浏览器和操作系统之上。测试系统功能——创建回归测试检验软件功能和用户需求。支持自动录制动作和自动生成.Net、Java、Perl等不同语言的测试脚本。
不显示窗口,PhantomJS - Scriptable Headless Browser
PhantomJS虚拟浏览器 phantomjs 是一个基于js的webkit内核无头浏览器 也就是没有显示界面的浏览器,利用这个软件,可以获取到网址js加载的任何信息
是单独一个可执行程序
https://github.com/ariya/phantomjs
https://phantomjs.org/download.html
xxxxxxxxxx
41pip install lxml
2
3import lxml
4from lxml import etree
lxml 是 Python 的第三方解析库,完全使用 Python 语言编写,它对 Xpath 表达式提供了良好的支持,因此能够了高效地解析 HTML/XML 文档。
http://c.biancheng.net/python_spider/lxml.html
依赖于lxml
https://pypi.org/project/beautifulsoup4/
https://www.crummy.com/software/BeautifulSoup/bs4/doc/
This document covers Beautiful Soup version 4.11.0. The examples in this documentation were written for Python 3.8.
xxxxxxxxxx
11pip install
类似于beautifulSoup ,语法接近jquery
pip install redis
https://www.selenium.dev/documentation/webdriver/getting_started/install_library/
Microsoft Edge 浏览器
Edge浏览器官网建议使用selenium4(此v4版本已经加入edge浏览器支持)