程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

A new generation of Python package management tools is coming!

編輯:Python

Hello everyone , I'm brother Yang .

Speaking of Python Package management tools , The first thing you think of must be pipconda And other classic tools .

But recently I found a novel Python Package management tools ——pdm, It is subject to PEP582https://www.python.org/dev/peps/pep-0582/) as well as node Inspired by the way of managing library files , Help us with 「 Local project library 」 Create and manage different Python Environmental Science .

1  Use pdm Manage the project library environment

1.1 pdm Installation

pdm There are many ways to install , Here we use the official recommended way to install :

python -m pip install --user pipx
python -m pipx ensurepath

Then close your terminal and restart a new one , Continue to input :

pipx install pdm

When the following appears , On behalf of us pdm The installation is complete ~

1.2 pdm The basic use of

Use pdm When creating a project with the current directory as the project warehouse , We need to according to the actual needs of the project , First switch to the corresponding Python Under the environment of version , Re execution pdm init To initialize the project , With 3.7 For example :

cd C:\Users\pengz\Desktop\ Current blog workbench \pdm-demo
conda activate dash-apps
pdm init

When initializing a project , Fill in each question according to your actual situation :

After the above process , You will find the created... In the current directory pyproject.toml file , It records the current pdm Basic parameters of the project :

Next, we can use... According to the actual needs of our project pdm add Command to install the specified single or multiple third parties Python library , With flask For example ( The first line of command is used to set the domestic pypi Mirror source ):

pdm config pypi.url https://pypi.douban.com/simple/
pdm add -v flask flask-login

After installation , We can see in the current directory __pypackages_ Catalog , The library we installed earlier is installed under it in isolation , similar node Of node_modules Catalog :

Also with the PEP582 The project structure advocated is consistent with :

foo
    __pypackages__
        3.7
            lib
                bottle
    myscript.py

In this way, the project level environment isolation effect is realized , Without creating additional virtual environments , To be in IDE Use in pdm The local isolation library execution program under the project is very simple , With pycharm For example , take pdm Open project as pycharm After the project , Find the position shown in the figure lib Folder , Mark it as Sources Root that will do , Also remember to select the interpreter as pdm init Corresponding to the environment during initialization :

Compare with the execution results of the original environment in the terminal , It can be found that environmental isolation has been successfully realized , This is because pdm Project __pypackages__ The package in will be in the environment itself site-packages Previously loaded , So as to better isolate the environment of the package :

If you want to restore a file in another path or on another machine pdm project , You just need to pyproject.toml And pdm.lock File copy past , Then execute... Under the corresponding directory pdm sync -v Command is enough , Very convenient , similar npm install coordination package.json The function of :

About pdm For more features, you can go to its official website https://pdm.fming.dev/ Learn more about .

-------- End --------

Selected materials

Reply key words , Get the corresponding data :

key word Data name 600《Python Knowledge Manual 》md《Markdown Quick reference table 》time《Python Time use guide 》str《Python String lookup table 》pip《Python:Pip Quick reference table 》style《Pandas Table style configuration guide 》mat《Matplotlib introduction 100 A case 》px《Plotly Express Visualization guide 》

Selected content

Data Science :VS Code in Python Configuration Guide | Financial tools Tushare | Matplotlib The most valuable 50 A chart

Book reading : How to read a book | Buffett's way | value | principle | The most important thing about investing | Davis Dynasty | Where is the customer's yacht | Deliberate practice | Lincoln | Pyramid principle

Investment summary :2021Q4 | 2021Q3 | 2021Q2 | 2021Q1 | 2020Q4

Featured Videos

visualization :Plotly Express

Finance and economics, :Plotly Application in the field of investment | draw K Line chart

Sorting algorithm : Summary | Bubble sort | Selection sort | Quick sort | Merge sort | Heap sort | Insertion sort | Shell Sort | Count sorting | Bucket sort | Radix sorting


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved