促銷活動

5U文學網(wǎng) > 實用文 > 活動方案 > 促銷活動 > poetry安裝,poet下載

poetry安裝,poet下載

| admin

Python 一鍵安裝全部依賴包

requirements.txt 用來記錄項目所有的依賴包和版本號,只需要一個簡單的 pip 命令就能完成。

生成的文件會像這個樣子

然后就可以用

來一次性安裝 requirements.txt 里面所有的依賴包,真是非常方便。

創(chuàng)建虛擬環(huán)境

激活虛擬環(huán)境

poetry 的工作方式就像 Node.js 里的 npm/yarn。

首先用 pip install poetry 來安裝它,可以用 poetry new [name] 來生成新項目,或者在項目的根目錄下面運行 poetry init 來初始化。

這樣 poetry 會在這個項目里創(chuàng)建一個 pyproject.toml 的文件,就像 package.json 一樣,里面記錄了項目所有的依賴包版本信息。

poetry install 可以一鍵安裝所有依賴包,還會生成 poetry.lock 文件,里面記錄了這次安裝時的依賴包。 poetry install --no-dev 可以只安裝生產(chǎn)環(huán)境的包,不安裝開發(fā)環(huán)境的包。

在 poetry add [name] 可以安裝 Flask 到生產(chǎn)環(huán)境,比如 poetry add flask ,再加 --dev 參數(shù), poetry add --dev flask 就會安裝到開發(fā)環(huán)境。

poetry remove [name] 可以卸載依賴包, poetry show 可以顯式安裝好的包。

更多用法請查看 poetry 。

python - Poetry介紹

一、簡介

Poetry 是一個Python 中的好用的包管理工具。在 Python 中,打包系統(tǒng)和依賴管理非常復(fù)雜:一個項目經(jīng)常要同時創(chuàng)建多個文件,例如:

setup.py

requirements.txt

setup.cfg

MANIFEST.in

Pipfile

基于此, poetry 將所有的配置都放置在一個 toml 文件中,包括:依賴管理、構(gòu)建、打包、發(fā)布等,可謂是簡單方便。

二、安裝

Poetry 要求 Python 版本為 2.7 或者 3.5+。Poetry 官方提供了一個腳本,可以快速方便地進行安裝。

osx / linux / bashonwindows 安裝:

curl -sSL | python -

windows powershell 安裝:

(Invoke-WebRequest -Uri -UseBasicParsing).Content | python -

Poetry 會被安裝在系統(tǒng)中的如下位置:

$HOME/.local/bin Unix系統(tǒng)

%APPDATA%\Python\Scripts Windows系統(tǒng)

然后把路徑添加到系統(tǒng)變量 PATH 中,即可使用 poetry 命令調(diào)用:

poetry --version

卸載:

python install-poetry.py --uninstall

POETRY_UNINSTALL=1 python install-poetry.py

如果你想要改變安裝的默認路徑,可以設(shè)置 POETRY_HOME :

POETRY_HOME=/etc/poetry python install-poetry.py

除了官方的安裝腳本,也可以使用 pipx 或者 pip 進行安裝:

pipx install poetry

pipx upgrade poetry

pipx uninstall poetry

pip install --user poetry

更新:

poetry self update

三、基礎(chǔ)使用

在已有項目中執(zhí)行:

poetry init

該命令創(chuàng)建了一個pyproject.toml 文件。你可以手動修改 pyproject.toml 文件添加依賴,然后運行:

poetry install

也可以執(zhí)行 add 命令安裝具體某個模塊并自動添加到 pyproject.toml:

$ poetry add xxxx

默認情況下,poetry會在 {cache-dir}/virtualenvs 下創(chuàng)建虛擬環(huán)境,你也可以手動修改該配置項,或者在 pyproject.toml 配置[virtualenvs.in-project] 在你的項目目錄中創(chuàng)建虛擬環(huán)境。

你可以使用 run 命令在虛擬環(huán)境中運行腳本:

poetry run python your_script.py

或者直接激活你的虛擬環(huán)境,新建一個 shell 運行:

poetry shell

只安裝dependencies :

poetry install --no-root

更新所有鎖定版本的依賴:

poetry update

四、命令選項

全局選項:

--verbose (-v|vv|vvv): "-v" 正常輸出, "-vv" 詳細輸出 "-vvv" debug

--help (-h) : 幫助信息

--quiet (-q) : 不輸出任何信息

--ansi: 強制 ANSI 輸出

--no-ansi: 禁止ANSI 輸出

--version (-V): 顯示版本

--no-interaction (-n): 禁止交互詢問

NEW:

poetry new my-package

創(chuàng)建項目模板,項目結(jié)構(gòu)如下所示:

my-package

├── pyproject.toml

├── README.md

├── my_package

│ └── init .py

└── tests

└── init .py

init:創(chuàng)建pyproject.toml文件 。

install:讀取pyproject.toml并安裝依賴,它具有如下這些選項:

--without: 忽略依賴

--with: 安裝可選的依賴

--only: 只安裝指定的依賴

--default: 只安裝默認的依賴

--sync: 同步鎖定的版本至環(huán)境中

--no-root: 不安裝根依賴包

--dry-run: 輸出操作但不執(zhí)行

--extras (-E): 安裝額外的包

update:升級包

poetry update

不指定任何包時,更新所有,也可以指定升級包:

poetry update requests toml

它具有如下選項:

--dry-run : 輸出操作但不執(zhí)行

--no-dev : 不按照開發(fā)依賴

--lock : 只更新鎖定不安裝

add: 添加依賴并安裝

限制范圍:

poetry add pendulum@^2.0.5

poetry add "pendulum=2.0.5"

它具有如下選項:

--group (-D): 分組

--editable (-e): 添加到編輯模式

--extras (-E): 添加額外的依賴

--optional: 添加至可選依賴

--python: 指定python版本

--platform: 指定操作系統(tǒng)

--source: 使用源名稱安裝

---allow-prereleases: 接受 prereleases 安裝

--dry-run: 輸出操作但不執(zhí)行

--lock: 只更新鎖定不安裝

remove:移除依賴

它具有如下選項:

--group (-D): 分組

--dry-run : 輸出操作但不執(zhí)行

show:列出所有的可安裝的包

如果你想看具體某個包的信息:

poetry show pendulum

name : pendulum

version : 1.4.2

description : Python datetimes made easy

dependencies:

--without: 忽略依賴

--with: 同時顯示

--only: 只顯示指定的依賴

--default: 只顯示默認的

--no-dev: 不顯示開發(fā)的依賴

--tree: 以樹狀形式顯示

--latest (-l): 展示最新的版本

--outdated (-o): 顯示最新版本,但僅適用于過時的軟件包

build:構(gòu)建

publish:發(fā)布

config:配置項

使用方法:

poetry config [options] [setting-key] [setting-value1] ... [setting-valueN]

它具有如下選項:

--unset: 刪除配置項

--list: 展示現(xiàn)在的配置

run:在虛擬環(huán)境中執(zhí)行命令

shell:激活虛擬環(huán)境

check:檢查pyproject.toml文件

search:搜索遠程包

lock:鎖定版本

version:顯示版本

export:導出鎖定的文件為其他的格式

poetry export -f requirements.txt --output requirements.txt

它具有如下選項:

--format (-f): 轉(zhuǎn)換的格式,暫時只支持requirements.txt

--output (-o): 輸出文件名字

--dev: 包括開發(fā)的依賴

--extras (-E): 額外的依賴

--without-hashes: 忽略哈希

--with-credentials: 包括合格證書

env:與虛擬環(huán)境進行交互

cache:緩存

顯示緩存列表:

poetry cache list

清除緩存:

poetry cache clear pypi --all

plugin:插件

安裝插件:

poetry plugin add poetry-plugin

顯示插件列表:

poetry plugin show

移除插件:

poetry plugin remove poetry-plugin

source: 倉庫源

添加源:

poetry source add pypi-test

顯示倉庫源列表:

poetry source show

移除:

poetry source remove pypi-test

五、配置

你可以運行config命令進行配置,或者直接修改config.toml文件,這個文件通常位于:

macOS: ~/Library/Application Support/pypoetry

Windows: C:\Usersusername\AppData\Roaming\pypoetry

Unix~/.config/pypoetry

可以使用--local命令對具體項目進行配置:

poetry config virtualenvs.create false --local

配置項:

cache-dir緩存目錄

installer.parallel并行安裝

virtualenvs.create如果不存在,則新建一個虛擬環(huán)境

virtualenvs.in-project在項目根目錄創(chuàng)建虛擬環(huán)境

virtualenvs.path虛擬環(huán)境路徑

virtualenvs.options.always-copy復(fù)制源文件還是創(chuàng)建鏈接到虛擬環(huán)境

virtualenvs.options.system-site-packages虛擬環(huán)境獲得系統(tǒng)包的權(quán)限

repositories.name設(shè)置一個新的可選倉庫

六、依賴配置

依賴的配置有很多種寫法:

版本限制:

尖括號:^1.2 代表 =1.2.0 2.0.0

波浪號:~1.2.3 代表 =1.2.3 1.3.0

星號:1.* 代表 =1.0.0 2.0.0

使用git倉庫:

[tool.poetry.dependencies]

requests = { git = " " }

使用本地路徑:

[tool.poetry.dependencies]

my-package = { path = "../my-package/", develop = false }

my-package = { path = "../my-package/dist/my-package-0.1.0.tar.gz" }

使用URL:

[tool.poetry.dependencies]

my-package = { url = " " }

python限制:

[tool.poetry.dependencies]

pathlib2 = { version = "^2.2", python = "~2.7" }

環(huán)境限制:

[tool.poetry.dependencies]

pathlib2 = { version = "^2.2", markers = "python_version ~= '2.7' or sys_platform == 'win32'" }

組合:

[tool.poetry.dependencies]

foo = [

{version = "=1.9", python = "^2.7"},

{version = "^2.0", python = "^3.4"}

]

如果限制很多,寫成一行不方便閱讀,可以寫成多行:

[tool.poetry.group.dev.dependencies]

black = {version = "19.10b0", allow-prereleases = true, python = "^3.6", markers = "platform_python_implementation == 'CPython'"}

寫成多行后:

[tool.poetry.group.dev.dependencies.black]

version = "19.10b0"

allow-prereleases = true

python = "^3.6"

markers = "platform_python_implementation == 'CPython'"

分組功能:

[tool.poetry.group.test.dependencies]

pytest = "^6.0.0"

pytest-mock = "*"

例如以上,就建立了一個test的組合的依賴。

下面這兩種寫法是等價的:

[tool.poetry.dev-dependencies]

pytest = "^6.0.0"

pytest-mock = "*"

或者:

[tool.poetry.group.dev.dependencies]

pytest = "^6.0.0"

pytest-mock = "*"

以上兩種寫法都聲明了一個dev的組的依賴。

聲明組合是可選的,這在具體的環(huán)境中有的特定的用途時很有用:

[tool.poetry.group.docs]

optional = true

[tool.poetry.group.docs.dependencies]

mkdocs = "*"

添加依賴到組中:

poetry add pytest --group test

同步依賴,只使用poetry.lock中的依賴,移除其他不是必須的依賴:

poetry install --sync

七、環(huán)境管理

Poetry可以為項目使用獨立的虛擬環(huán)境,而不是使用系統(tǒng)安裝的。

切換環(huán)境:

poetry env use /full/path/to/python

poetry env use python3.7

poetry env use system

顯示當前激活的環(huán)境信息:

poetry env info

運行命令會輸出如下信息:

Virtual environment

Python: 3.7.1

Implementation: CPython

Path: /path/to/poetry/cache/virtualenvs/test-O3eWbxRl-py3.7

Valid: True

System

Platform: darwin

OS: posix

Python: /path/to/main/python

列出所有的虛擬環(huán)境列表:

poetry env list

刪除環(huán)境:

poetry env remove /full/path/to/python

poetry env remove python3.7

poetry env remove 3.7

poetry env remove test-O3eWbxRl-py3.7

高頻英語近義詞用法辨析

一. advise/persuade/suggest的用法區(qū)別

1. suggest

① 當"建議"解,可接名詞、動名詞和賓語從句,不能接不定式。

May I suggest going (to go 誤) there by train?

我建議坐火車去那里如何?

② suggest還可接句型“to sb.+從句”。

I suggested to him that John (should) be fired.

我向他建議把約翰開除。

2. advice / advise

作"勸告,忠告"解,有下列四種用法:

advise sth.或doing sth.

advise sb. (not) to do sth.

advise sb. against sth.或doing sth.

advise(sb.) that sb.(should) do sth.

She advised prudence.

她勸告(我們)應(yīng)謹慎從事。

He advised waiting till the proper time.

他勸告(我們)等到適當時機才行動。

I advised him (not) to do it now.

我勸他現(xiàn)在(不要)做此事。

I advised him against doing it now.

我勸他不要現(xiàn)在做此事。

I advised (him) that he (should) do it now.

我勸他現(xiàn)在就做此事。

advise后面加sb. (not) to do...,而suggest后面必須加sb.(或者sb.'s)doing...,當然兩者都可以接賓語從句,注意賓語從句的動詞形式必須是(should) (not) do...。如下面三個句子:

a.I advise my father to stop smoking.

b.I suggest my father( father's) stopping smoking.

c.I advise/suggest (that) my father (should) stop smoking.

3. persuade

后面接sb. to do...,它的特別之處是它表示結(jié)果,不表示動作,是"成功地勸說,說服"的意思。

I advise my father to stop smoking but I can't persuade him to.

我勸說我父親戒煙,但是我沒能說服成功。

此外advise與persuade之間可以轉(zhuǎn)換,try to persuade=advise, manage to advise=persuade。

二. every和each的用法區(qū)別

1. each可作代詞和形容詞,而every只能用作形容詞。如可以說each of these dictionaries或each one of these dictionaries, 但不能說every of these dictionaries, 該用every one of these dictionaries.

2. each可指兩個或兩個以上中間的每一個,而every只可指三個或三個以上中間的每一個,不能指兩個中每一個.如:

可以說each of my eyes, 不可說every one of my eye,但可說every one of my toes(腳趾) .

3. each通常用來指若干固定數(shù)目中的每一個,而every往往指“任何一個”,如:

Each girl sitting over there is my student.

坐在那里的每一女孩子都是我的學生。

Every man must do his best.

人人都盡最大的努力。

4. every和not連用,即“every…not”或“not…every”構(gòu)成部分否定,表示“并非每一個”的意思,each則無此結(jié)構(gòu).

5. every+ 基數(shù)詞+ 復(fù)數(shù)名詞=every+ 序數(shù)詞+ 單數(shù)名詞,作“每(多少)”解,但each不能用于這一結(jié)構(gòu)中. 如: every three days 每三天或每隔兩天,相當于 every third day.

6. every two days, every second day都作“每隔一天”解,但在實際應(yīng)用中人們都用every other day來表示這一意思,every two days也有人講,而every second day則用的很少。

7. 也可以說every few days, 相當于漢語的“隔些日子”.

8. each 可以與other構(gòu)成固定的搭配,即each other意思為“彼此、相互、互相”的意思,而every則不能.

三. poem與poetry的用法區(qū)別

1. poem的意思是“詩”,為可數(shù)名詞,可指具體的一首詩、兩首詩、幾首詩等;用作主語時,謂語動詞的`數(shù)取決于poem的數(shù)(即poem為單數(shù),謂語動詞用單數(shù);poem為復(fù)數(shù),謂語動詞用復(fù)數(shù))。poet 詩人。如:

This poem is worth learning by heart.

這首詩是值得背誦的。

His poems have been compared to those of the English Romantics.

他的詩歌被拿來與英國浪漫主義詩歌相提并論。

2. poetry的意思也是“詩”,但為詩的總稱,是不可數(shù)名詞;用作主語時,謂語動詞總是用單數(shù)。如:

This writer’s poetry reflects his love of nature.

該作者的詩反映出他熱愛自然。

Poetry has been composed since ancient times.

從古時起人們就開始創(chuàng)作詩歌了。

Poetry serves to stimulate the mind.

詩歌能激發(fā)心靈。

四. attend / join / take part in 的用法區(qū)別

1. attend 指參加會議、婚禮、葬禮、典禮;去上課,上學,聽報告等;句子的主語只是去聽,去看,自己不定起積極作用。如:

He will attened an important meeting tomorrow.

他明天會出席一個很重要的會議。

2. join 指加入一某個黨派,團體組織等,成為其中其成員之一,意為“參軍、入團、入黨”等。

和某人一起做某事,其結(jié)構(gòu)為:join sb in (doing)sth 根據(jù)上下文,in (doing)sth 也可以省去。

She joined the Young Pioneers.

她加入了少先隊員。

Will you join us in the discussion ?

你會加入我們的討論嗎?

3. take part in 指積極參加會議或群眾性活動等,著重說明句子主語參加該項活動并在活動中發(fā)揮作用。

We often take part in physical labour.

我們經(jīng)常參加體力勞動。

五. beautiful, pretty, good-looking, handsome的用法區(qū)別

1. beautiful

beautiful 表示“美”,可用于人或事物。用于人時,通常只用于形容女性或小孩,一般不用于男性。它表示的“美”主要指能“給感官以極大的快樂(giving great pleasure to the senses)”,它側(cè)重從客觀上表明一種接近理想狀態(tài)的美,語氣很強。如:

It’s a beautiful village.

那是個美麗的村莊。

She is a beautiful girl.

她是個美麗的女孩。

The film star is really beautiful.

這位電影明星的確很美。

2. pretty

pretty 主要表示“漂亮”、“俊俏”、“標致”等義,可用于人(主要是女性和小孩)或事物,語氣比 beautiful 弱。它往往側(cè)重從主觀上評述某人或某物,含有“可愛”或“討人喜歡”之意。如:

What a pretty dress!

多漂亮的連衣裙啊!

They have a pretty daughter.

他們有個漂亮的女兒。

She is not really beautiful, but she looks pretty when she smiles.

她其實長得并不美,但笑起來很好看。

注:偶爾用于男性,但通常帶有貶義。

3. good-looking

good-looking 意為“好看的”,主要用于人(男人、女人或小孩),不常用于事物。如:

He (She) is good-looking.

他(她)長得很帥(漂亮)。

有時用于事物,但不多見。如:

He has a good-looking car (horse).

他有一輛(匹)好看的汽車(馬)。

4. handsome

handsome 意為“英俊的”,主要用于男性,但有時也用于女性(一般只用于成年女性,不用于少女),意為“體態(tài)健美的”、“端莊穩(wěn)重的”。如:

He is a handsome young man.

他是一個英俊的年輕人。

Do you discribe her as beautiful or handsome?

你是說她貌美還是說她健美?

有時可用于事物,但不多見。如:

It’s a handsome building.

那是棟漂亮的建筑。

六. repair, mend 與 fix 的用法區(qū)別

三個詞都可以譯為“修理”,但fix一詞在美語中應(yīng)用更為廣泛。

1. repair的對象范圍很廣。常指大件或構(gòu)造較復(fù)雜的事物,如鐘表、收音機、汽車和機床等大型物體?;蛴糜谛拗虊?、道路和建筑等。

I have to have my watch repaired.

我的表該修理了。

repair a road/ bridge

修理公路/橋梁

2. mend一般用于“修補”破損的東西,如衣服、鞋襪、傘和桌椅等整體物體上的裂縫、破洞。

Will you please mend the sleeve of my blouse?

請你把我襯衣的袖子補一下好嗎?

3. fix一般用于“修理”構(gòu)造較復(fù)雜的事物,如鐘表、收音機、機器等。側(cè)重于“安裝”、“調(diào)整”。常用于美國口語中。

The workers are fixing the machine.

工人們在安裝機器。

Have you had your watch fixed?

你已找人修你的表了嗎?

七. genius / gift / talent 的用法區(qū)別

   三個詞都有“天賦,才能”之意。

1. genius 程度最高,指“最全面的天賦” 也指“有天賦的人”。

Li Bai was a great genius.

李白是一個偉大的天才。

2. gift 側(cè)重“天賦”

He has a gift for music.

他有音樂天賦。

3. talent n.才能,有才能的人

have a talent for 有...…的才能

talented adj. 有才能的

My sister has a talent for music.

我的姐姐有音樂天賦。

八. at last,finally與in the end的用法區(qū)別

1. finally可以放在句首,也可放在動詞前。有兩個用法:一是在列舉事物或論點時,用來引出最后一項內(nèi)容;二是用在句中動詞前面,表示“等了好久才…”。如:

She put some soil in the box, then sowed the seed carefully, and then covered it with more soil.Finally she kept the box in the shade.

她在盒子里放些土,然后仔細地播種,之后再蓋上一些土,最后她把盒子放在陰涼處。

We waited and waited, and the train finally arrived.

我們等了又等,火車終于來了。

Finally I’d like to thank you all for your coming .

最后我要感謝諸位的光臨。(不能用at last)

Finally we finished the work. = We finally finished the work.

最后我們完成了這項工作。

2. in the end放在句首或句末,表示“經(jīng)過許多變化、困難或捉摸不定的情況之后,某事才發(fā)生”,有時可與finally互相換用,其反義詞是in the beginning,但in the end不能置于動詞前。如:

We found that small village in the end.

我們終于找到了那個小村莊。

He tried several times,and in the end he succeeded.

他嘗試過多次,最后成功了。

3. at last指經(jīng)過,周折,等待,耽擱后的“最后,終于”得到所期待的結(jié)果,常常帶有較濃厚的感情色彩。at last也可用來表示“等候或耽誤了很多時間之后才……”,語氣比較強烈。如:

At last , he passed the exam .

最后他終于通過了考試。

At last the work was done and he could rest.

最后工作完成了,他可以休息了。

She has come at last!

她總算來了。

He worked harder than before, and he passed the English examination at last.

他比以前學習更加努力,終于通過了英語考試。

九. laugh,laughing與laughter的用法區(qū)別

三者用作名詞時,均表示“笑”,但有區(qū)別:

1. laugh 側(cè)重指行為,是可數(shù)名詞。如:

He answered with a laugh.

他笑著回答。

2. laughing側(cè)重指笑的動作,是不可數(shù)名詞。如:

He held his laughing.

他忍住了笑。

3. laughter 具有抽象或概括意義,是不可數(shù)名詞 。如:

In this case there is no cause for laughter.

這沒什么好笑的。

The room was full of laughter and happiness.

房間里充滿了歡聲笑語。

十. litter 和rubbish的用法區(qū)別

litter 和 rubbish 都可指“垃圾”,用作不可數(shù)名詞。

rubbish 指“沒用的東西(被扔或?qū)⒁獊G棄的無用的東西)”不可回收。

litter 指“(室內(nèi)或公共場所)亂扔的廢物(紙屑、不要的包裝紙、廢瓶等)”還可回收。

Throw the rubbish out.

把垃圾扔出去。

Pick up your litter after a picnic.

野餐后將廢棄物收拾好。

mitmproxy_概述和使用_2021-10-14

一、本次接口自動化工具要用到的內(nèi)容

1、用于公司沒有接口文檔,但是我還想知道所有的接口,做自動化

2、schedule可以做線上監(jiān)控

3、mitmproxy+python用于自動抓取接口

4、jinjia2+flask+layui+多線程,用于前端網(wǎng)頁,前臺展示測試結(jié)果

5、argparse用于生成命令行操作

6、poetry打包,用于發(fā)布線上,用戶安裝使用

二、mitmproxy的好處

1、定制化高

2、維護成本低

3、用例擴展速度快

三、mtimproxy?安裝方式

? ? ? ?? 安裝方式

四、介紹mitmproxy一些常用方法:

def request(flow):

? ? # 獲取請求對象? ? request = flow.request

? ? # 實例化輸出類? ? info = ctx.log.info

? ? # 打印請求的url? ? info(request.url)

? ? # 打印請求方法? ? info(request.method)

? ? # 打印host頭? ? info(request.host)

? ? # 打印請求端口? ? info(str(request.port))

? ? # 打印所有請求頭部? ? info(str(request.headers))

? ? # 打印cookie頭? ? info(str(request.cookies))

????? body

????? flow.request.urlencoded_form? #獲取urlencoded表單類型body

????? flow.request.multipart_form #獲取復(fù)合表單類型body

????? flow.request.get_text()? #獲取所有類型的body

????? # 所有服務(wù)器響應(yīng)的數(shù)據(jù)包都會被這個方法處理

# 所謂的處理,我們這里只是打印一下一些項def response(flow):

? ? # 獲取響應(yīng)對象? ? response = flow.response

? ? # 實例化輸出類? ? info = ctx.log.info

? ? # 打印響應(yīng)碼? ? info(str(response.status_code))

? ? # 打印所有頭部? ? info(str(response.headers))

? ? # 打印cookie頭部? ? info(str(response.cookies))

? ? # 打印響應(yīng)報文內(nèi)容? ? info(str(response.text))

224097