इस ट्यूटोरियल में, हम सीखेंगे कि पायथन पैकेजों को स्थापित करने और प्रबंधित करने के लिए पाइप का उपयोग कैसे करें।
पाइप क्या है?
pip
पायथन के लिए मानक पैकेज प्रबंधक है। हम pip
अतिरिक्त पैकेज स्थापित करने के लिए उपयोग कर सकते हैं जो पायथन मानक पुस्तकालय में उपलब्ध नहीं हैं। उदाहरण के लिए,
pip install numpy
यदि हमने pip
अपने सिस्टम पर स्थापित किया होता, तो यह कमांड numpy
लाइब्रेरी स्थापित करता ।
पाइप कैसे स्थापित करें?
pip
पायथन संस्करणों 3.4 या पुराने पर पूर्व-स्थापित आता है। हम pip
कंसोल में निम्नलिखित कमांड का उपयोग करके स्थापित कर सकते हैं :
pip --version
यदि pip
सिस्टम में पहले से ही उपलब्ध है, तो संबंधित pip
संस्करण प्रदर्शित किया जाता है, जैसे:
सी से 19.3.1 पाइप: Python37 lib साइट-संकुल पाइप (अजगर 3.7)
यदि हम पायथन के किसी पुराने संस्करण का उपयोग कर रहे हैं या pip
किसी अन्य कारण से स्थापित नहीं है, तो इस लिंक में वर्णित चरणों का पालन करें: स्थापना
पाइप का उपयोग करना
pip
एक कमांड लाइन कार्यक्रम है। इसकी स्थापना के बाद, एक pip
कमांड जोड़ा जाता है जिसे कमांड प्रॉम्प्ट के साथ उपयोग किया जा सकता है।
पाइप का मूल सिंटैक्स है:
pip
पाइप के साथ पैकेज स्थापित करना
मानक पायथन पुस्तकालय के अलावा, पायथन समुदाय विभिन्न विकास रूपरेखाओं, उपकरणों और पुस्तकालयों के लिए सिलसिलेवार व्यापक पैकेज में योगदान देता है।
इनमें से अधिकांश पैकेजों को आधिकारिक तौर पर पायथन पैकेज इंडेक्स (PyPI) में होस्ट और प्रकाशित किया जाता है। pip
हमें इन पैकेजों को डाउनलोड और इंस्टॉल करने की अनुमति देता है।
मूल पैकेज स्थापना
install
आदेश का उपयोग पैकेज इंस्टॉल करने के लिए इस्तेमाल किया pip
। आइए एक उदाहरण लेते हैं:
मान लीजिए कि हम स्थापित करना चाहते हैं requests
, तो पाइथन के लिए एक लोकप्रिय HTTP लाइब्रेरी। हम इसे निम्न कमांड की मदद से कर सकते हैं।
pip install requests
आउटपुट
कैश्ड https://files.pythonhosteded.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190227c11b4b7fb/requests-2.22.0-py2.py3-none-whone-any-whone-any-when-any-when पर उपयोग करके अनुरोध एकत्रित करना .pythonhosted.org। //files.pythonohhosted.org/packages/b4/40/a9837291310ee1ccc242ceb6ebfd9eb21539649f193a7c8c86ba15b9b939/urllib3-1.25.7-py2.py3-none-any.whl/adlive idna = 2.53 आईडी आईडी आईडी का उपयोग करके। / 2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl कलेक्टिंग सर्टिफिकेट> = 2017.4.17 डाउनलोडिंग https: //files.pythonhostorg / package / b9 / 63 / df50cac98ea0d5b006c55a399c3bf1db9da7b5a24de7890bc9cfd5dd9e99 (प्रमाण-पत्र-2019.11.28-py2.py3-none-any.whl। इंस्टॉल किया जा रहा है। 3.0.4 इडना-2.8 अनुरोध-2.22.0 urllib3-1.25.7
यहां, हम देख सकते हैं कि जिस पैकेज को हम इंस्टॉल करना चाहते हैं, उसके नाम के बाद कमांड का pip
उपयोग किया गया है install
( requests
)।
अन्य सभी निर्भरता की तरह chardet
, urllib3
और certifi
इस पैकेज के लिए आवश्यक भी द्वारा स्थापित कर रहे हैं pip
।
पैकेज संस्करण निर्दिष्ट करना
जब pip
install
इसका न्यूनतम रूप में उपयोग किया जाता है, pip
तो पैकेज का सबसे हाल का संस्करण डाउनलोड करता है।
कभी-कभी, केवल एक विशिष्ट संस्करण अन्य कार्यक्रमों के साथ संगत होता है। तो, हम निम्नलिखित तरीके से पैकेज के संस्करण को परिभाषित कर सकते हैं:
पाइप स्थापित अनुरोध == 2.21.0
यहां, हमने requests
लाइब्रेरी का 2.11.0 संस्करण स्थापित किया है ।
पाइप के साथ स्थापित संकुल को सूचीबद्ध करना
pip list
आदेश वर्तमान अजगर वातावरण में सभी उपलब्ध संकुल सूची के लिए इस्तेमाल किया जा सकता है।
pip list
आउटपुट
पैकेज संस्करण ---------- ---------- सर्टिफिकेट 2019.11.28 chardet 3.0.4 idna 2.8 pip 19.3.1 अनुरोध 2.22.0 setuptools 45.0.0 urllib3 1.25.7 पहिया 0.33 .6
पाइप शो के साथ पैकेज की जानकारी
pip show
एक या अधिक इंस्टॉल किए गए पैकेज के बारे में जानकारी आदेश को प्रदर्शित करता है। आइए एक उदाहरण देखें:
pip show requests
आउटपुट
नाम: अनुरोध संस्करण: 2.22.0 सारांश: मनुष्य के लिए पायथन एचटीटीपी। मुख पृष्ठ: http://python-requests.org लेखक: केनेथ रिट्ज लेखक-ईमेल: [email protected] लाइसेंस: Apache 2.0 स्थान: c: users dell desktop venv lib साइट "संकुल की आवश्यकता है सर्टिफिकेट, चर्डेट, urllib3, idna Required-by:
यहां, show
कमांड requests
लाइब्रेरी के बारे में जानकारी प्रदर्शित करता है । सूचना की आवश्यकता होती है और आवश्यक-से ऊपर उत्पादन में स्तंभ।
requests
लाइब्रेरी के लिए कौन सी निर्भरता आवश्यक है, यह कॉलम दिखाता है । और, आवश्यक-बाय कॉलम उन पैकेजों को दिखाता है जिनकी आवश्यकता होती है requests
।
पाइप के साथ पैकेज की स्थापना रद्द करना
हम कमांड के pip
साथ प्रयोग करके पैकेज को अनइंस्टॉल कर सकते हैं pip uninstall
।
मान लीजिए हम requests
अपने वर्तमान पायथन परिवेश से पुस्तकालय को हटाना चाहते हैं। हम इसे निम्नलिखित तरीके से कर सकते हैं:
pip uninstall requests
आउटपुट
अनुरोधों को अनइंस्टॉल करना-2.22.0: हटा देगा: C: Python37 lib site- पैकेज request-2.22.0.dist-info * C: Python37 lib साइट-पैकेज request * आगे बढ़ना (y /) n)? y सफलतापूर्वक रद्द किए गए अनुरोध -२.२.०
जैसा कि हम देख सकते हैं, requests
पैकेज को अंतिम संकेत के बाद हटा दिया गया है।
Note: Even though the specified package is removed, the packages that were installed as dependencies are not removed. In this case, the dependencies (chardet
, urllib3,
and certifi)
of the requests
library aren't uninstalled.
If we need to remove the dependencies of a package as well, we can use the pip show
command to view installed packages and remove them manually.
Using Requirement Files
A file containing all the package names can also be used to install Python packages in batches.
Let's take a look at an example:
Suppose we have a file requirements.txt which has the following entries:
numpy Pillow pygame
We can install all these packages and their dependencies by using a single command in pip
.
pip install -r requirements.txt
Output
Collecting numpy Using cached https://files.pythonhosted.org/packages/a9/38/f6d6d8635d496d6b4ed5d8ca4b9f193d0edc59999c3a63779cbc38aa650f/numpy-1.18.1-cp37-cp37m-win_amd64.whl Collecting Pillow Using cached https://files.pythonhosted.org/packages/88/6b/66f502b5ea615f69433ae1e23ec786b2cdadbe41a5cfb1e1fabb4f9c6ce9/Pillow-7.0.0-cp37-cp37m-win_amd64.whl Collecting pygame Using cached https://files.pythonhosted.org/packages/ed/56/b63ab3724acff69f4080e54c4bc5f55d1fbdeeb19b92b70acf45e88a5908/pygame-1.9.6-cp37-cp37m-win_amd64.whl Installing collected packages: numpy, Pillow, pygame Successfully installed Pillow-7.0.0 numpy-1.18.1 pygame-1.9.6
Here, we have used the same install
command with pip
.
However, the additional argument -r
specifies pip
that we are passing a requirements file rather than a package name.
Creating Requirements File
As an alternative to manually creating the requirements file, pip
offers the freeze
command. Let's look at how to use this command.
Suppose our current Python environment has the following packages. It can be displayed using pip list
.
Package Version ---------- ------- numpy 1.17.0 Pillow 6.1.0 pip 19.3.1 pygame 1.9.6 setuptools 45.0.0 wheel 0.33.6
The packages that don't come preinstalled will Python are listed using the freeze
command.
pip freeze
Output
numpy==1.17.0 Pillow==6.1.0 pygame==1.9.6
The pip freeze
command displays the packages and their version in the format of the requirements file.
So this output can be redirected to create a requirements file using the following command:
pip freeze> requirements.txt
A new requirements.txt file is created in the working directory. It can later be used in other Python environments to install specific versions of packages.
Search packages in pip
The search
command is used to search for packages in the command prompt. Let's look at an example:
pip search pygame
Output
pygame-anisprite (1.0.0) - Animated sprites for PyGame! pygame-ai (0.1.2) - Videogame AI package for PyGame pygame-engine (0.0.6) - Simple pygame game engine. pygame-assets (0.1) - Assets manager for Pygame apps pygame-gui (0.4.2) - A GUI module for pygame 2 pygame-spritesheet (0.2.0) - Python pygame extension that provides SpriteSheet class. pygame-minesweeper (1.0) - Minesweeper game implemented in python using pygame pygame-menu (2.1.0) - A menu for pygame, simple, lightweight and easy to use pygame-plot (0.1) - Quick visualization of data using pygame with a matplotlib style pygame (1.9.6) - Python Game Development…
Here, we have searched for a library called pygame
. All other packages that match the keyword are displayed. This command is helpful for finding related packages.
pip
यात्रा के बारे में अधिक जानने के लिए: पायथन पाइप (आधिकारिक दस्तावेज)