0% found this document useful (0 votes)
50 views

Pip PDF

Uploaded by

Vitan Bogdan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Pip PDF

Uploaded by

Vitan Bogdan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

© 2017 – Python Programming

v 1.0

pip & virtualenv

In mod traditional un package se downloadeaza si


apoi se instaleaza astfel:

cd package_dir

python setup.py install

Medoda de mai sus foloseste modulul distutils inclus


in stadard library, care este un set de tool-uri pt.
packaging si distribution of code.

Pentru un managemenul eficient si usor al package-


urilor se foloseste insa un manager de pachete
precum pip si easyinstall

Intalare pip

sudo apt install python3-pip #linux only


pip3 install setuptools #este o librarie, dependinta pt. pip
pip3 install --upgrade pip #actulizare pip la ultima versiune

Instalare package
# Example: pip install [package name]
# Let's install the excellent *requests* library
pip install requests

© 2017 – Crystal Mind Academy


Informatiile continute in acest document reprezinta proprietate intelectuala Crystal Mind Academy
Distribuirea sau reproducerea de orice fel este interzisa.
-1-
© 2017 – Python Programming
v 1.0

Gasirea si instalarea unei versiuni anume


# Example: pip install [package name]==[version]
# Let's install version 2.0.0. of requests
pip install requests==2.0.0

Instalarea de la un URL, exemplu github


# Example: pip install [url]
# Let's install virtualenv
pip install https://github.com/pypa/virtualenv/tarball/1.9.X

Stergere package
# Example: pip uninstall [package name]
# Let's remove requests library
pip uninstall requests

Upgrade package
# Example: pip install --upgrade [package name]
# Let's upgrade requests library
pip install --upgrade requests

Cautarea unui package


# Example: pip search [package name]
# Let's find all django packages
# This might take a while (there's tonnes of them!)
pip search django

Informatii despre un package

© 2017 – Crystal Mind Academy


Informatiile continute in acest document reprezinta proprietate intelectuala Crystal Mind Academy
Distribuirea sau reproducerea de orice fel este interzisa.
-2-
© 2017 – Python Programming
v 1.0

pip show package-name

Creare unei liste cu package-urile instalate cu pip


(freeze)
#Example: pip freeze > [file name.ext]
#Let's list all the packages currently installed
#daca suntem in venv arata doar package-urile din
#venv, altfel pe toate
#venv trebuie sa fie activate
pip freeze > package_list.txt

# Example: pip freeze -r [existing file.ext] >


[filename.ext]
# Let's append new packages installed after the
last freeze
pip freeze package_list.txt > package_list_new.txt

Instalare unei liste de package-uri dintr-un fisier


(creat anterior cu freeze)

Dupa ce cream lista package-urilor necesare folosind


freeze, le instalam usor din fisier.

# Example: pip install -r [file name.ext]

# Let's install back all the packages from the


previous example
#util cand venv este activat, lucreaza doar in venv
© 2017 – Crystal Mind Academy
Informatiile continute in acest document reprezinta proprietate intelectuala Crystal Mind Academy
Distribuirea sau reproducerea de orice fel este interzisa.
-3-
© 2017 – Python Programming
v 1.0

pip install -r package_list_new.txt

Virtual Environment (virtualenv)

virtualenv reprezinta modul recomandat de lucru cu


proiectele Python.

Avantaje:

- environment fresh si izolat pt. proiectele Python

- se pot instala package-uri fara drepturi


administrative

- crearea de liste cu dependinte si reinstalarea


usoara a acestora cu pip

- portability across systems

Instalare virtual environment

https://packaging.python.org/guides/installing-
using-pip-and-virtualenv/
sudo apt-get install -y python3-venv #linux only

mkdir environments
cd environments
© 2017 – Crystal Mind Academy
Informatiile continute in acest document reprezinta proprietate intelectuala Crystal Mind Academy
Distribuirea sau reproducerea de orice fel este interzisa.
-4-
© 2017 – Python Programming
v 1.0

Va crea directorul my_env cu toate fisierele


necesare (module, pip, python interpreter etc)
python3 -m venv my_env

Activarea environmentului
Linux:
source my_env/bin/activate

Windows:
Set-ExecutionPolicy -Scope CurrentUser →
RemoteSigned
.\Scripts\activate

Virtual environment trebuie dezactivat la final:


deactivate

Pornirea IDLE in venv

Pe Windows 10 sau Linux din venv din Powershell


sau Bash pornim IDLE: .\python.exe -m idlelib

© 2017 – Crystal Mind Academy


Informatiile continute in acest document reprezinta proprietate intelectuala Crystal Mind Academy
Distribuirea sau reproducerea de orice fel este interzisa.
-5-

You might also like