AdSense

網頁

2025/6/16

Python PDM建立新專案

Python使用PDM建立新專案。


環境

  • Windows 11 Pro
  • Python 3.13.3


事前要求

參考「Windows 11 Python套件管理工具 PDM安裝」安裝PDM。


建立專案

開啟命令列輸入pdm new [project]在當前目錄建立一個新專案,[project]為建立的專案目錄名稱,例如輸入pdm new demo建立一個名為demo的專案目錄。輸入後需要回答一些提示問題:

pdm new demo
Creating a pyproject.toml for PDM...
INFO: Using the first matched interpreter.
Virtualenv is created successfully at C:\..\demo\.venv
Project name (demo)
Project version (0.1.0)
Do you want to build this project for distribution(such as wheel)?
If yes, it will be installed by default when running `pdm install`. [y/n] (n):
License(SPDX name) (MIT):
Author name (user):
Author email (youremail):
Python requires('*' to allow any) (==3.13.*):
INFO: Git repository initialized successfully.
Project is initialized successfully

執行後即在當前目錄會產生一個專案目錄,檔案內容如下:

.git/
.venv/
__pycache__
.gitignore
.pdm-python
pyproject.toml

在專案目錄中以命令列輸入pdm info顯示專案資訊:

C:\..\demo>pdm info
PDM version:
  2.25.2
Python Interpreter:
  C:\..\demo\.venv\Scripts\python.exe (3.13)
Project Root:
  C:/../demo
Local Packages:

PDM預設會使用virtualenv虛擬環境,也就是依賴會存在專案跟目錄下的.venv目錄。


沒有留言:

AdSense