Yuav Sau Li Cas Python Script (nrog Duab)

Cov txheej txheem:

Yuav Sau Li Cas Python Script (nrog Duab)
Yuav Sau Li Cas Python Script (nrog Duab)

Video: Yuav Sau Li Cas Python Script (nrog Duab)

Video: Yuav Sau Li Cas Python Script (nrog Duab)
Video: Военные тактические часы-Топ-10 самых жестких военных ч... 2024, Tej zaum
Anonim

Nab hab sej yog hom lus nrov heev rau kev ua haujlwm. Tab sis yuav ua li cas yog tias tus neeg ua haujlwm koj txoj haujlwm tsis xav tau lossis paub yuav ua li cas thiaj sau ntawv Python? Kab lus no yuav qhia koj yuav ua li cas sau cov ntawv Python rau hauv qhov ua tiav.

Cov kauj ruam

Txoj Kev 1 ntawm 2: Siv CX_Freeze

Txheeb Python Script Step 1
Txheeb Python Script Step 1

Kauj Ruam 1. Rub tawm cx_Freeze los ntawm Sourceforge

Nws yog cov cuab yeej rau ntim Python cov ntawv sau rau hauv cov khoom siv ib leeg.

Txheeb Python Script Step 2
Txheeb Python Script Step 2

Kauj Ruam 2. Ua kom ntseeg tau tias koj tab tom ua haujlwm ntawm lub platform koj xav tau koj cov haujlwm kom ua tiav

Piv txwv li, yog tias koj xav tsim Windows cov ntawv ua tiav, khiav cx_Freeze ntawm Windows. Tib yam mus rau Mac thiab Linux.

Txheeb Python Script Step 3
Txheeb Python Script Step 3

Kauj Ruam 3. Tsim cov ntaub ntawv Python tshiab hu ua setup.py hauv cov npe ntawm Python program koj xav sau

Txheeb Python Script Step 4
Txheeb Python Script Step 4

Kauj Ruam 4. Sau cov cai hauv qab no rau hauv koj cov ntaub ntawv tshiab setup.py

(Raws li ib txwm nyob hauv Python, kev nkag ncaj yog qhov tseem ceeb, thiab hmoov tsis tau tshwm ntawm no vim muaj teeb meem kev teeb tsa.):

    ntshuam sys los ntawm cx_Freeze ntshuam teeb tsa, Ua tiav lub hauv paus = Tsis muaj yog tias sys.platform == 'win32': puag = 'Win32GUI' executables = [Ua tiav (Python npe lub npe, puag = puag)) teeb tsa (lub npe = executable_name, version = 'version ', piav qhia =' desc ', executables = executables)

Txheeb Python Script Step 5
Txheeb Python Script Step 5

Kauj Ruam 5. Khiav cov lus txib hauv qab no hauv koj lub computer lub davhlau ya nyob twg:

    cd [txoj hauv kev rau koj li Python cov ntawv teev npe] python setup.py tsim

Txheeb Python Script Step 6
Txheeb Python Script Step 6

Kauj Ruam 6. Saib rau daim nplaub tshev tshiab hu ua "tsim" hauv Python program's directory

Nws yuav tsum tau tsim thaum lub sijhawm dhau los. Qhib lub nplaub tshev thiab daim nplaub tshev hauv nws.

  • Muaj koj executable! Lwm cov ntaub ntawv hauv phau ntawv teev npe no yuav tsum tau ua kom tiav koj li kev ua haujlwm, yog li nco ntsoov khaws cia nrog kev ua tiav.
  • Kev tsim kho tuaj yeem ua raws ntau txoj hauv kev. Saib cx-freeze.readthedocs.org txhawm rau piav qhia txhua qhov ua tau.

Txoj Kev 2 ntawm 2: Siv PyInstaller

Pip nruab pyinsatller
Pip nruab pyinsatller

Kauj Ruam 1. Qhib lub davhlau ya nyob twg lossis hais kom sai thiab ua raws li cov cai hauv qab no

Qhov no yuav nruab pyInstaller.

    pip nruab pyinstaller

Helloworld dir
Helloworld dir

Kauj Ruam 2. Qhib phau ntawv teev npe nyob qhov twg cov ntawv nab nab nyob

Ntawm Windows "Txoj Cai Nyem" thaum tuav "Ua haujlwm" thiab xaiv "qhib qhov rai hais kom ua ntawm no". Ntawm linux "Txoj Cai Nyem" thiab xaiv "Qhib Terminal".

Pyinstaller npe py
Pyinstaller npe py

Kauj Ruam 3. Ntaus cov lus txib no los sau koj cov ntawv

Tos kom cov lus txib ua tiav.

    pyInstaller script_name.py

Helloworld py
Helloworld py
Dist dir
Dist dir

Kauj Ruam 4. Txav mus rau hauv phau ntawv teev npe tshiab "dist"

Koj qhov phiaj xwm ua ke yuav nyob ntawd.

Lus ceeb toom

  • Teeb lub hauv paus = 'Win32GUI' raws li tau hais los saum no yuav ua teeb meem yog tias koj li Python code suav nrog kev nkag () ua haujlwm.
  • Sim teeb lub hauv paus = 'Console', lossis lub hauv paus = Tsis muaj txij li Console yog lub neej ntawd.

Pom zoo: