先看教程: 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
xxxxxxxxxx321PS D:\kava\python> pip install numpy2Collecting numpy3 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:005Installing collected packages: numpy6Successfully installed numpy-1.22.37WARNING: 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>> ^C11PS D:\kava\python> py12Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win3213Type "help", "copyright", "credits" or "license" for more information.14>>> exit15Use exit() or Ctrl-Z plus Return to exit16>>> exit17Use exit() or Ctrl-Z plus Return to exit18>>> exit19Use exit() or Ctrl-Z plus Return to exit20>>> exit()21PS D:\kava\python> py -m pip install --upgrade pip22Requirement already satisfied: pip in c:\users\amos\appdata\local\programs\python\python310\lib\site-packages (22.0.4)23Collecting pip24 Downloading pip-22.1-py3-none-any.whl (2.1 MB)25 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 3.5 MB/s eta 0:00:0026Installing collected packages: pip27 Attempting uninstall: pip28 Found existing installation: pip 22.0.429 Uninstalling pip-22.0.4:30 Successfully uninstalled pip-22.0.431Successfully installed pip-22.132PS D:\kava\python>
python 标准库位置: %python安装路径%\Lib
x1# 进入python IDE环境,执行如下命令可以查看基础库列表2
3PS F:\Users\Amos\Desktop> python4Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win325Type "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 sched10_abc _tkinter glob secrets11_aix_support _tracemalloc graphlib select12_ast _uuid gzip selectors13_asyncio _warnings hashlib setuptools14_bisect _weakref heapq shelve15_blake2 _weakrefset hmac shlex16_bootsubprocess _winapi html shutil17_bz2 _xxsubinterpreters http signal18_codecs _zoneinfo idlelib site19_codecs_cn abc idlexlib smtpd20_codecs_hk aifc imaplib smtplib21_codecs_iso2022 antigravity imghdr sndhdr22_codecs_jp argparse imp socket23_codecs_kr array importlib socketserver24_codecs_tw ast inspect sqlite325_collections asynchat io sre_compile26_collections_abc asyncio ipaddress sre_constants27_compat_pickle asyncore itertools sre_parse28_compression atexit json ssl29_contextvars audioop keyword stat30_csv base64 lib2to3 statistics31_ctypes bdb linecache string32_ctypes_test binascii locale stringprep33_datetime binhex logging struct34_decimal bisect lzma subprocess35_distutils_hack builtins mailbox sunau36_elementtree bz2 mailcap symtable37_functools cProfile marshal sys38_hashlib calendar math sysconfig39_heapq cgi mimetypes tabnanny40_imp cgitb mmap tarfile41_io chunk modulefinder telnetlib42_json cmath msilib tempfile43_locale cmd msvcrt test44_lsprof code multiprocessing textwrap45_lzma codecs netrc this46_markupbase codeop nntplib threading47_md5 collections nt time48_msi colorsys ntpath timeit49_multibytecodec compileall nturl2path tkinter50_multiprocessing concurrent numbers token51_opcode configparser numpy tokenize52_operator contextlib opcode trace53_osx_support contextvars operator traceback54_overlapped copy optparse tracemalloc55_pickle copyreg os tty56_py_abc crypt pathlib turtle57_pydecimal csv pdb turtledemo58_pyio ctypes pickle types59_queue curses pickletools typing60_random dataclasses pip unicodedata61_sha1 datetime pipes unittest62_sha256 dbm pkg_resources urllib63_sha3 decimal pkgutil uu64_sha512 difflib platform uuid65_signal dis plistlib venv66_sitebuiltins distutils poplib warnings67_socket doctest posixpath wave68_sqlite3 email pprint weakref69_sre encodings profile webbrowser70_ssl ensurepip pstats winreg71_stat enum pty winsound72_statistics errno py_compile wsgiref73_string faulthandler pyclbr xdrlib74_strptime filecmp pydoc xml75_struct fileinput pydoc_data xmlrpc76_symtable fnmatch pyexpat xxsubtype77_testbuffer fractions queue zipapp78_testcapi ftplib quopri zipfile79_testconsole functools random zipimport80_testimportmultiple gc re zlib81_testinternalcapi genericpath reprlib zoneinfo82_testmultiphase getopt rlcompleter83_thread getpass runpy84
85Enter any module name to get more help. Or, type "modules spam" to search86for modules whose name or summary contain the string "spam".87
88>>>89>>>90>>>
python 第三方库位置: %python安装路径%\Lib\site-packages
xxxxxxxxxx121# 查看已安装的第3方扩展库列表及版本2pip list3或4pip freeze5
6# 验证第3方库是否安装,已安装时无信息输出7
8>>> import matplotlib9Traceback (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/ 直接下载最新版安装包,页面说明。
类库分类:解析库、工具库、存储库
xxxxxxxxxx151C:\Users\Amos>where python2
3C:\Users\Amos\AppData\Local\Programs\Python\Python310\python.exe4C:\Users\Amos\AppData\Local\Microsoft\WindowsApps\python.exe5C:\Program Files\Inkscape\bin\python.exe6
7C:\Users\Amos>8
9## 查看路径 10C:\Users\Amos>pip -V11pip 22.1 from C:\Users\Amos\AppData\Local\Programs\Python\Python310\lib\site-packages\pip (python 3.10)12
13C:\Users\Amos>pip3 -V14pip 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
xxxxxxxxxx61pip install virtualenv2pip3 install virtualenv3
4pip install virtualenvwrapper5pip 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
xxxxxxxxxx41pip install lxml23import lxml4from 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.
xxxxxxxxxx11pip install
类似于beautifulSoup ,语法接近jquery
pip install redis
https://www.selenium.dev/documentation/webdriver/getting_started/install_library/
Microsoft Edge 浏览器
Edge浏览器官网建议使用selenium4(此v4版本已经加入edge浏览器支持)