http://wahnfried.net
- intro
예전에 돌려놓고도 빈둥대던 차에 글을 올리지 못하다가, 설날 연휴를 맞이해서 간단한 가이드를 올립니다. 물론 복사해 붙여넣기가 대부분이지요. 대부분의 내용들은 py2exe 홈페이지 (http://py2exe.org)에서 가져온 것들입니다. 일단은 py2exe홈페이지에서 py2exe를 다운받아서 설치해주세요.
Tutorial
py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. Python is needed on the computer where py2exe itself is run because py2exe is a Python program and it includes parts of Python in the package that is built.
To successfully complete this tutorial you'll need to know the basics of Python (you can get started at python.org's getting started page). You'll also need to know how to run Python programs from the command prompt.
There are a few simple steps needed to use py2exe once you've installed it:
Create/test your program
The biggest step is almost always the first one. The good news is that py2exe typically has little or no impact on this step. The vast majority of things you can do with Python will work with py2exe. Many modules just work seamlessly with py2exe, but some third party modules will require a little extra work. Luckily there is help available at WorkingWithVariousPackagesAndModules.
It's important that you make sure everything is working before you use py2exe. If py2exe fixes a broken program, then that's probably a bug in py2exe that needs to be fixed!
The first example we'll use here is our old friend...
1 print "Hello World!"We need to make sure it's working...
C:\Tutorial>python hello.pyHello WorldC:\Tutorial>
Looks good!
Create your setup script (setup.py)
*** 여기를 잘 읽어주세요. setup script를 작성하신 뒤 아래와 같이 실행하면 executable 생성이 가능하답니다. ***
py2exe extends Distutils with a new "command". If you've installed third party Python modules then there's a good chance you've seen at least one distutils command:
C:\Tutorial>python setup.py install
"install" is a Distutils command that installs something (typically a Python module or package). The details Distutils needs to do that installation are contained in setup.py (and sometimes other associated files).
"py2exe" is a new Distutils command that is added when you import py2exe. To use py2exe you need to create a setup.py file to tell Distutils and py2exe what you want to do. Here's a setup.py who's simplicity is appropriate for our sample program...
1 from distutils.core import setup
2 import py2exe
3
4 setup(console=['hello.py'])Notice that this is ordinary Python. Let's go through it line by line...
- When working with py2exe the only part of Distutils we'll typically need to reference directly is the setup function, so that's all we'll import.
- Once Distutils is loaded, we need to load py2exe so that it can add its command.
- Whitespace is good!
- Call setup and tell it that we want a single console application and the main entry point is "hello.py".
Run your setup script
The next step is to run your setup script. Make sure to give the py2exe command and expect to see lots and lots of output:
C:\Tutorial>python setup.py py2exe running py2exe*** searching for required modules ****** parsing results ***creating python loader for extension 'zlib'creating python loader for extension 'unicodedata'creating python loader for extension 'bz2'*** finding dlls needed ****** create binaries ****** byte compile python files ***byte-compiling C:\Tutorial\build\bdist.win32\winexe\temp\bz2.py to bz2.pycbyte-compiling C:\Tutorial\build\bdist.win32\winexe\temp\unicodedata.py to unicodedata.pycbyte-compiling C:\Tutorial\build\bdist.win32\winexe\temp\zlib.py to zlib.pycskipping byte-compilation of c:\Python24\lib\StringIO.py to StringIO.pyc[skipping many lines for brevity]skipping byte-compilation of c:\Python24\lib\warnings.py to warnings.pyc*** copy extensions ****** copy dlls ***copying c:\Python24\lib\site-packages\py2exe\run.exe -> C:\Tutorial\dist\hello.exe*** binary dependencies ***Your executable(s) also depend on these dlls which are not included,you may or may not need to distribute them.Make sure you have the license if you distribute any of them, andmake sure you don't distribute files belonging to the operating system. ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll USER32.dll - C:\WINDOWS\system32\USER32.dll SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dllC:\Tutorial>
Two directories will be created when you run your setup script... build and dist. The build directory is used as working space while your application is being packaged. It is safe to delete the build directory after your setup script has finished running. The files in the dist directory are the ones needed to run your application. If you are using Python 2.4 or newer then MSVCR71.dll will be included in dist - this is a Microsoft DLL and you need to determine if you have the legal right to distribute it.
Test your executable
Now that the package has been created it is ready to test:
C:\Tutorial>cd distC:\Tutorial\dist>hello.exeHello World
Excellent, it works!!!
- Outro
아직 간단한 예제들만 만져보느라 겪어보지는 못했습니다만, 많은 외부 모듈이나 패키지들을 이용한 프로젝트를 py2exe를 통해 빌드하다 보면 해당 모듈을 알아서 찾지 못할 때가 있다고 합니다. 이전 버전의 py2exe에서만 그런 것인지는 모르겠지만, 그런 경우를 보게 되면 또 한 번 방법을 찾아보아야겠네요. 재미있는 프로그램들을 많이 만들어 봐야겠습니다.



Adidas NBA Jerseys , Cheap NBA Basketball Jerseys ,Wholesale NBA Basketball Jerseys ,
Adidas NBA Basketball Jerseys ,Throwback NBA Jerseys ,Authentics NBA Jerseys
Atlanta Hawks Jerseys , Boston Celtics Jerseys , Kevin Garnett Jerseys , Charlotte Bobcats Jerseys
chicago bulls Jerseys , Cleveland Cavaliers Jerseys ,Lebron James Jerseys ,Shaq Oneal Jerseys ,
Dallas Mavericks Jerseys ,Jason Kidd Jerseys , Denver Nuggets Jerseys , Detroit Pistons Jerseys
Houston Rockets Jerseys , Los Angeles Clippers Jerseys , Los Angeles Lakers Jerseys ,
Kobe bryants Lakers , Miami Heat Jerseys , Dwayne Wade Jerseys , Minnesota Timberwolves Jerseys ,
New Orleans Hornets Jerseys ,Chris Paul Jerseys , Orlando Magic Jerseys ,
vince carter Jerseys ,Dwight Howard Jerseys , Phoenix Suns Jerseys , Steve Nash Jerseys ,
Portland TrailBlazers Jerseys , Roy Jerseys , Sacramento Kings Jerseys , San Antonio Spurs Jerseys ,
Tim Duncan Jerseys , Utah Jazz Jerseys , Deron Williams Jerseys , Washington Wizards jerseys
Cheap basketball jerseys , Wholesale basketball jerseys , Discount basketball jerseys , Youth basketball jerseys
NBA basketball jerseys Sale ,NBA basketball jerseys for Sale