Nyob hauv Python, siv Python tej pob khoom luam tawm los ntawm lwm tus neeg tsim tawm hauv koj tus kheej qhov project yog ib yam uas yuav ua rau koj lub neej yooj yim dua. Python Package Index, lossis PyPI, yog qhov chaw khaws ntaub ntawv loj ntawm cov lej koj tuaj yeem siv. Kawm paub yuav ua li cas kom koj pib nrog PyPI thiab nws qhov program installer, PIP (Package Installer for Python).
Cov lus qhia no yuav tsum ua haujlwm ntawm macOS version txhawb los ntawm Python installer tam sim no, uas suav nrog v10.6+ (Snow Leopard) rau 32-ntsis installer, thiab v10.9 (Mavericks) rau 64-ntsis- tsuas yog version ntawm tus installer tam sim no.
Yuav ua li cas rau nruab PIP ntawm macOS
PIP yog lub neej ntawd pob installer thiab tsis ntev los no tau ntxiv rau cov tub ntxhais faib ntawm Python. Qhov no txhais tau tias rau nruab PIP peb yuav tsum nruab Python.
Thaum Python 2 tau siv los ua ntej teeb tsa hauv macOS, koj yuav tsum siv cov ntawv tshiab dua, Python 3. Tsuas yog vim li cas thiaj siv txuas ntxiv v2.7 yog los txhawb cov laus, cov ntawv thov uas twb muaj lawm. Hmoov zoo, yog tias koj nyuam qhuav pib, koj tsis muaj cov no.
Python installation yog tus qauv. PKG-raws li kev sib raug zoo. Txhawm rau kom nws nce thiab khiav, ua cov kauj ruam hauv qab no:
-
Ua ntej, lub taub hau mus rau Python lub vev xaib thiab rub tawm qhov tseeb tshaj tawm. Tshwj tsis yog tias koj nyob hauv lub tshuab qub thiab yuav tsum tau siv macOS version dhau los rau qee qhov laj thawj, rub tawm 64-ntsis installer cov ntaub ntawv.
- Nov yog tus qauv macOS. PKG hom, yog li koj tuaj yeem nyem rau ntawm cov ntaub ntawv installer kom ncaws tawm.
-
thawj lub vijtsam yuav muab qee cov ntaub ntawv ntawm kev teeb tsa, nyem Txuas ntxivtxhawm rau txav mus.
-
Click Continue ntawm nplooj ntawv nram qab no ib yam nkaus, uas qhia rau koj paub tias qhov project yuav tsum tsis txhob muab kev txhawb nqa rau 32-ntsis installers los ntawm v3.8 mus rau.
-
Lub vijtsam tom ntej hais kom koj lees txais daim ntawv tso cai rau Python. Nyem Continue, then click Agree.
-
Koj yuav tsum xaiv lub hom phiaj rau kev teeb tsa ntawm lub vijtsam hauv qab no. Koj tuaj yeem nyem Install tso rau hauv koj lub ntsiab tsav, lossis nyem Customize yog tias koj muaj lwm qhov hauv siab. Koj tseem yuav tau sau koj tus password mus ntxiv.
-
Tam sim no tus installer yuav pib luam cov ntaub ntawv.
- Thaum qhov kev teeb tsa tiav lawm, lub app lub nplaub tshev yuav qhib hauv Finder.
Xam Python Install ntawm macOS
Lub installation muaj ob peb yam khoom, raws li hauv qab no:
- Ob. RTF cov ntaub ntawv: Ib zaug muaj Daim Ntawv Tso Cai; lwm cov ntaub ntawv ReadMe.
- Ob. COMMAND cov ntaub ntawv: Cov no muaj los pab ua qee qhov kev teeb tsa. Cov ntaub ntawv Install Certificates.command yuav teeb tsa qee daim ntawv pov thawj SSL, thiab cov ntaub ntawv hloov tshiab Plhaub Profile.command yuav pab yog tias koj muaj teeb meem siv Python 3, thiab pom tias koj ib txwm raug coj mus rau Python 2.
- IDLE app: Ib puag ncig kev txhim kho kev sib koom ua ke tshwj xeeb rau Python.
- Python Launcher: Pab koj txhim kho qee qhov chaw cuam tshuam txog kev xa tawm Python scripts.
Yuav ua li cas kom paub meej tias Python ua haujlwm ntawm macOS
Ua ntej koj tuaj yeem siv Python, nws yog qhov zoo tshaj kom paub meej tias koj Python installation ua haujlwm raug.
-
Sim cov lus txib hauv qab no hauv Terminal:
python --version
Python 3.7.4
-
Yog tias koj xav paub ntxiv txog tej yam, sim khiav ib tsab ntawv Python yooj yim. Nkag mus (lossis muab tshuaj txhuam) cov lej hauv qab no rau hauv cov ntawv khoob thiab muab nws lub npe "hello-world.py":
print ("Hello World!")
-
Tam sim no, ntawm qhov hais kom ua, khiav cov hauv qab no:
python \path\to\hello-world.py
Hello World!
Yuav Ua Li Cas Siv Python's PIP ntawm macOS
Peb paub tam sim no Python ua haujlwm, thiab peb tuaj yeem hloov mus siv PIP.
Zoo hmoo, tsis muaj dab tsi ua ntawm no: PIP los nruab tawm-ntawm-lub-lub thawv ntawm cov ntawv tshiab ntawm Python. Hais tias, koj yuav tsum paub koj tus kheej nrog nws.
-
Siv cov lus txib hauv qab no hauv Terminal yuav muab koj cov ntsiab lus ntawm PIP txhua yam hais txog:
pip --help
-
Thawj qhov koj yuav xav ua yog nrhiav pob uas koj tuaj yeem siv, thiab nrhiav pip yog qhov koj xav tau rau qhov ntawd. Nws yuav tshawb xyuas Python Package Index (PyPI) rau koj lub sijhawm tshawb nrhiav.
xav tias peb xav tsim peb daim ntawv thov Python kom txuag tau tus password. macOS twb muaj ib tug zoo mechanism rau qhov no: Keychain. Cov lus txib hauv qab no yuav qhia cov npe ntawm tag nrho cov pob hauv PyPI nrog lo lus tseem ceeb "keychain":
pip nrhiav keychain
-
Nyob rau hauv cov txiaj ntsig, muaj ib pob hu ua macos-keychain, uas yog qhov peb tab tom nrhiav. Yog li, es tsis txhob coding tej yam xws li lo lus zais nkag, encryption, thiab hooking rau hauv cov txheej xwm txheej xwm, peb tsuas yog download tau qhov no thiab integrate rau peb cov kev xav tau. Koj tuaj yeem nruab ib pob nrog cov lus txib hauv qab no:
pip nruab macos-keychain
-
Hmoov tsis zoo, hloov kho tag nrho cov pob teeb tsa tsis yooj yim li hloov kho Linux faib. Koj yuav tsum ua li ntawd rau txhua pob thaum koj pom tias nws tsis muaj hnub kawg. Siv cov lus txib hauv qab no:
pip nruab macos-keychain --upgrade
-
Thaum kawg, tshem ib pob yog yooj yim li:
pip uninstall macos-keychain