vault backup: 2025-01-21 14:38:40
This commit is contained in:
		| @ -19,17 +19,29 @@ tags: | |||||||
| - Commands | - Commands | ||||||
| 	- 將虛擬環境建立的位置設至專案資料夾內(統一放在專案資料夾內很方便啊!想移除整個環境的話直接把它刪掉就好) | 	- 將虛擬環境建立的位置設至專案資料夾內(統一放在專案資料夾內很方便啊!想移除整個環境的話直接把它刪掉就好) | ||||||
| 		- ``poetry config virtualenvs.in-project true`` | 		- ``poetry config virtualenvs.in-project true`` | ||||||
| 	- 初始化專案並產出pyproject.toml | 	- 初始化專案並提供互動式介面協助產出pyproject.toml | ||||||
| 		- ``poetry init`` | 		- ``poetry init`` | ||||||
| 	- 創立或進入某個python版本的虛擬環境中(poetry依據python版本切分虛擬環境) | 	- 創立某個python版本的虛擬環境(poetry依據python版本切分虛擬環境) | ||||||
| 		- ``poetry env use python3.x`` | 		- ``poetry env use python3.x`` | ||||||
|  | 	- 新增套件(可以套用extra及version,例如"requests\[security,socks\]~=2.22.0") | ||||||
|  | 		- ``poetry add [package_name]`` | ||||||
|  | 	- 更新套件 | ||||||
|  | 		- ``poetry update [package_name]`` | ||||||
|  | 	- 移除套件(沒有被其他套件依賴的依賴套件也一併會被移除) | ||||||
|  | 		- ``poetry remove [package_name]`` | ||||||
| 	- 透過pyproject.toml產生poetry.lock環境檔(通常在修改完前者後執行) | 	- 透過pyproject.toml產生poetry.lock環境檔(通常在修改完前者後執行) | ||||||
| 		- ``poetry lock`` | 		- ``poetry lock`` | ||||||
| 	- 將poetry.lock環境檔套用至虛擬環境中(實際上安裝套件至venv的部分!) | 	- 將poetry.lock環境檔套用至虛擬環境中(實際上安裝套件至venv的部分!) | ||||||
| 		- ``poetry install`` | 		- ``poetry install`` | ||||||
| 	- 輸出requirements.txt | 	- 產生進入虛擬環境的指令(不像conda那樣直接進入虛擬環境,而是會產生類似``source .venv/bin/activate``的指令) | ||||||
|  | 		- ``poetry env activate`` | ||||||
|  | 	- 輸出requirements.txt檔 | ||||||
| 		1. 安裝export插件(poetry2.0以上版本需要自己裝) | 		1. 安裝export插件(poetry2.0以上版本需要自己裝) | ||||||
| 			- ``pipx inject poetry poetry-plugin-export`` | 			- ``pipx inject poetry poetry-plugin-export`` | ||||||
| 		2. 執行指令 | 		2. 執行指令 | ||||||
| 			- ``poetry export --without-hashes --format=requirements.txt > requirements.txt`` | 			- ``poetry export --without-hashes --format=requirements.txt > requirements.txt`` | ||||||
| 			- 或 ``poetry export -f requirements.txt --output requirements.txt`` (帶有hash值) | 			- 或 ``poetry export -f requirements.txt --output requirements.txt`` (帶有hash值) | ||||||
|  | 	- 秀出環境的套件以及其依賴套件(會繃出一棵很美的樹喔!) | ||||||
|  | 		- ``poetry show --tree`` | ||||||
|  | 	- 打包並發布專案 | ||||||
|  | 		- ``poetry publish --repository [repo_name] --username [user_name] --password [password] --build --skip-existing`` | ||||||
		Reference in New Issue
	
	Block a user