Pip, Basics, da Python Management Package

game da pip

A cikin labarin na gaba zamuyi la'akari da yadda zamu iya sarrafa abubuwan Python ta amfani da Pip. Kamar wanene kuma wanda ya rage zai san cewa wannan shine mai gudanarwa na kunshin Python. Ana iya amfani da shi don girkawa, sabuntawa, da cire fakitoci waɗanda aka rubuta a cikin harshen shirye-shiryen Python.

Sunan maimaitawa ne wanda za'a iya fassara shi azaman Mai Sanya Kunshin Pip o Mai Sanya Kayan Wuta. Wannan tsarin sarrafa kunshin mai sauki ne wanda ake amfani dashi don shigarwa da gudanar da kunshin da za'a iya samu a cikin Lissafin Kunshin Python (PyPI). Python 2.7.9 kuma daga baya (a cikin jerin Python2), Python 3.4 kuma daga baya sun hada da wannan manajan (pip3 don Python3) tsoho.

Shigarwa

Don shigar da wannan manajan kunshin kan Debian da Ubuntu, kawai zamu bude tashar (Ctrl + Alt + T) sannan mu rubuta:

sudo apt-get install python3-pip

Hakanan zamu iya shigar da pip daga fayil ɗin python. Dole ne kawai mu aiwatar:

wget https://bootstrap.pypa.io/get-pip.py

sudo python get-pip.py

Lura cewa get-pip.py shima zai girka saitin kantuna y dabaran.

Sabunta PIP

Wannan manajan kunshin Za'a shigar dashi idan muna amfani da Python 2> = 2.7.9 ko Python 3> = 3.4. Zamu iya sabunta shi ta amfani a cikin tashar:

sudo pip install -U pip

Don sabunta komai (pip, saitunan sanyi, whell), Za mu kashe:

sudo pip install --upgrade pip setuptools wheel

San wane siga aka girka

Idan muna so mu san shigar sigar wannan manajan kunshin, za mu kashe:

sigar pip

pip --version

Irƙirar mahalli na kamala

Kafin shigar da kowane kunshin Python, ana ba da shawarar don ƙirƙirar yanayin kamala. Yankunan kamala na Python suna ba mu damar shigar da kunshin Python a keɓe wuri maimakon duniya.

Bari mu ce muna buƙatar shigar da kunshin Python, misali youtube-dl, wanda ke buƙatar fasalin 1 na LibFoo, amma wani aikace-aikacen yana buƙatar fasali na 2. A cikin wannan halin yana da sauƙi a ƙare da sabunta ba da gangan ba aikace-aikacen da bai kamata a sabunta su ba. Don kauce wa wannan, muna ware fakitin a cikin yanayin kamala. Duk mahalli na kamala suna da kundin adireshi na shigarwa kuma basa cuxanya ko rikici da juna.

Zamu iya ƙirƙirar keɓaɓɓun yanayin Python ta amfani da kayan aiki guda biyu:

  • Zo.
  • virtualenv.

Idan kana amfani Python 3.3 kuma daga baya, an shigar da Venv ta tsohuwa. Ga wannan misali Ni Ina amfani da Python 2.x, kuma ina buƙatar shigar da virtual. Don yin wannan zan yi gudu:

sudo pip install virtualenv

Irƙiri yanayi na kamala ta amfani da virtualenv

kama-da-wane yanayi virtuallen-pip

virtualenv NOMBRE

source NOMBRE/bin/activate

Da zarar ka kunna umarnin da ke sama, za a sanya ka a cikin kewayen ka nan da nan. Domin musaki yanayi mai kyau kuma komawa zuwa kwasfa na al'ada, gudu:

deactivate

Sarrafa fakitin Python

Yanzu zamu ga mafi amfani na yau da kullun. Don ganin ta jerin dukkan umarnin da ake dasu da kuma zabi Janar kawai za mu kashe:

pip

Idan bukata learnara koyo game da umarni, kamar wanda aka girka, zamu aiwatar:

pip install --help

Sanya fakiti

Da farko za mu je ƙirƙirar yanayi mai kyau kamar yadda aka nuna a cikin masu zuwa. A cikin wannan misalin zan yi amfani da virtuallen kawai.

virtualenv MIENV

Sauya MIENV da sunanka. A ƙarshe, kunna shi ta amfani da umarni:

source MIENV/bin/activate

Da zarar kun gudu umarnin da ke sama, za ku kasance a cikin yanayin kama-da-wane. Yanzu ne lokacin shigar da fakiti. Don shigar misali YouTube-dl, gudu:

saka bututu youtube-dl

pip install youtube-dl

Wannan umarnin zai girka youtube-dl tare da duk masu dogaro da shi.

Sanya sigar kunshin

para shigar da takamaiman sigar, gudu:

pip install youtube_dl=2017.12.14

para shigar da sigar banda wacce aka ƙayyade, gudu:

pip install youtube_dl!=2017.12.14

Zazzage fakiti

para zazzage fakiti tare da duk masu dogaro (ba tare da girka shi ba), gudu:

pip download youtube-dl

Lissafa duk abubuwanda aka sanya

Don nemo waɗanne kunshin da aka sanya, za mu gudu:

pip list

Wannan umarnin zai nuna duk fakitin da aka sanya ta amfani da wannan manajan.

Binciken fakiti

para bincika takamaiman kunshin, misali youtube-dl, gudu:

pip binciken youtube-dl

pip search youtube-dl

Sabunta fakiti

para sabunta tsoffin kayan aiki, gudu:

pip install --upgrade youtube-dl

para jera dukkan abubuwanda basu da amfani a cikin tsarin shafi, gudu:

pip list --outdated --format=columns

Yanzu, sabunta tsofaffin fakiti zuwa sabbin sigar da ake dasu amfani da umarni:

pip freeze --local | grep -v '^\e' | cut -d = -f 1 | xargs -n1 pip install -U

Cire fakiti

para cirewa / cire kunshin da aka girka, gudu:

pip uninstall youtube-dl

Don cire wasu kunshin dole ne mu rubuta su tare da sarari tsakanin su.

Idan muna so cire duk abubuwan fakitin da aka sanya ta amfani da manajan kunshin, za mu kashe:

pip freeze | xargs pip uninstall -y

Taimako

taimaka pip

A wannan gaba zamu sami ra'ayi game da mai sarrafa kunshin Python da yadda ake amfani dashi. Amma wannan shine ƙarshen ƙarshen duk abin da za mu iya yi. Don ƙarin cikakkun bayanai da zurfin ciki, zamu iya tuntuɓar takaddun hukuma da kuma sashen taimako kara –Help zuwa sunan mai sarrafa fayil.


Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Wanda ke da alhakin bayanan: Miguel Ángel Gatón
  2. Manufar bayanan: Sarrafa SPAM, sarrafa sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

      juliuco nike m

    Godiya, zai zama mafi cikakken labarin game da umarnin pip