Programing

간단한 Python 스크립트를 Windows 실행 파일로 변환하는 프로세스

lottogame 2020. 10. 13. 07:14
반응형

간단한 Python 스크립트를 Windows 실행 파일로 변환하는 프로세스


이 질문에 이미 답변이 있습니다.

Windows 사용자의 일상 생활에 도움이 될 스크립트를 작성했습니다. 나는 단순히 그녀에게 .exe를 보내고 그녀에게 파이썬, dll을 설치하거나 추가 파일을 처리하도록 요청하지 않고 싶습니다.

Python 스크립트를 실행 파일로 컴파일하는 것과 관련된 많은 stackoverflow 항목을 읽었습니다. 많은 옵션이 있지만 일부는 날짜가 지났고 (2008 년 이후 업데이트 없음) 약간 혼란스럽고 몇 시간을 보낸 후 지금 당장 묻지 않을만큼 단순한 것은 없습니다.

이 작업을 수행하는 더 나은 최신 방법이 있기를 바랍니다.

나는 조사했다 :

그러나 나는 그들을 일하게 할 수 없거나 필요한 결과를 얻는 방법을 이해할 수 없었습니다. 내가 얻은 가장 가까운 것은 py2exe를 사용했지만 여전히 MSVCR71.dll을주었습니다.

py2exe 또는 다른 도구를 사용하는 방법에 대한 사전 이해가 필요한 일부 조정 답변을 따를 수 없었으므로 단계별 답변을 주시면 감사하겠습니다.

모듈 중 하나는 해당 버전에서만 사용할 수 있으므로 Python 2.5를 사용하고 있습니다.


--onefile옵션 을 사용하면 PyInstaller는 단일 파일 실행 파일을 생성합니다 (실제로 수행하는 작업은 추출한 다음 자체 실행됩니다).

여기에 간단한 PyInstaller 튜토리얼이 있습니다 . 사용에 대해 궁금한 점이 있으면 게시 해주세요.


py2exe를 사용하여 setup.py에 다음을 포함하십시오.

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 1}},
    windows = [{'script': "YourScript.py"}],
    zipfile = None,
)

그런 다음 명령 프롬프트 / 유휴를 통해 실행할 수 있으며 둘 다 나를 위해 작동합니다. 도움이되기를 바랍니다.


http://sourceforge.net/projects/py2exe/files/latest/download?source=files이동하여 py2exe를 다운로드하는 것이 좋습니다 . 그런 다음 setup.py라는 파이썬 파일을 만듭니다. 그 안에 입력

from distutils.core import setup
import py2exe
setup(console=['nameoffile.py'])

사용자 폴더에 저장 변환하려는 파일도 동일한 폴더에 저장하십시오.

창의 명령 프롬프트 유형을 실행하십시오. setup.py install py2exe

여러 줄의 코드를 인쇄해야합니다 ...

다음으로 dist 폴더를 엽니 다.

exe파일을 실행 하십시오.

프로그램이 작동하는 데 필요한 파일이 있으면 해당 폴더로 이동하십시오.

dist 폴더를 사람에게 복사 / 보내기.

선택 사항 : dist 폴더의 이름 변경

작동하기를 바랍니다! :)


내가 추천에 @Nicholas에 가입 할 pyInstaller 중에을 합니다 (로 --onefile플래그), 그러나 경고 : 할 수 없습니다 은 "최신 버전"을 사용 pyInstaller 중에 1.3 - 그것의 세. "시험판"1.4를 사용하여 여기 에서 다운로드 하거나 svn repo 의 코드를 더 잘 사용하여 SVN을 설치하고 svn co http://svn.pyinstaller.org/trunk pyinstaller.

@Nicholas가 암시 하듯이 동적 라이브러리는 나머지 실행 파일과 동일한 파일에서 실행할없지만 다행스럽게도 다음 과 같이 임시 디렉토리에 자체 압축을 해제하는 "자체 풀기"실행 파일에 나머지 모든 파일을 함께 압축 할 수 있습니다. 필요; PyInstaller는 이것에 대해 좋은 일을합니다 (그리고 다른 많은 것들에서- py2exe더 인기가 있지만 pyinstaller제 생각에는 다른 모든 측면에서 좋습니다).


1) Python 버전에 따라 여기 에서 py2exe를 가져옵니다 .

2) 변환하려는 스크립트와 같은 폴더에 "setup.py"라는 파일을 만듭니다. 다음 코드를 사용합니다.

from distutils.core import setup
import py2exe
setup(console=['myscript.py']) #change 'myscript' to your script

3) 명령 프롬프트로 이동하여 해당 폴더로 이동하고 다음을 입력합니다.

python setup.py py2exe

4) It will generate a "dist" folder in the same folder as the script. This folder contains the .exe file.


you may want to see if your app can run under IronPython. If so, you can compile it to an exe http://www.codeplex.com/IronPython


You can create executable from python script using NSIS (nullsoft scriptable install system). Follow the below steps to convert your python files to executable.

  • Download and install NSIS in your system.
  • Compress the folder in .zip file that you want to export into executable.
  • Start NSIS and select Installer based on ZIP file. Find and provide path to your compressed file.

  • Provide your Installer Name and Default Folder path and click on Generate to generate your exe file.

  • Once its done you can click on Test to test executable or Close to complete the process.

  • The executable generated can be installed to system and can be distributed to use this application without even worrying about installing the required python and its packages.

For video tutorial follow: How to Convert any Python File to .EXE


You could create an installer for you EXE file by:
1. Press WinKey + R
2. Type "iexpress" (without quotes) into the run window
3. Complete the wizard for creating the installation program.
4. Distribute the completed EXE.

참고URL : https://stackoverflow.com/questions/2136837/process-to-convert-simple-python-script-into-windows-executable

반응형