Tutorial - py. 2exe. 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 py. 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. You'll also need to know how to run Python programs from the command prompt. There are a few simple steps needed to use py. The Microsoft Visual C++ 2010 Redistributable Package installs runtime components of Visual C++ Libraries required to run applications developed with Visual C++ on a. Create/test your program. Create your setup script (setup. Run your setup script. Test your executable. Providing the Microsoft Visual C runtime DLLBuild an installer if applicable. Create/test your program. The biggest step is almost always the first one. The good news is that py. The vast majority of things you can do with Python will work with py. Many modules just work seamlessly with py. ![]() ![]() Luckily there is help available at Working. With. Various. Packages. And. Modules. It's important that you make sure everything is working before you use py. If py. 2exe fixes a broken program, then that's probably a bug in py.
The first example we'll use here is our old friend.. C: \Tutorial> python hello. Hello World! Create your setup script (setup. Distutils with a new . 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. The details Distutils needs to do that installation are contained in setup. To use py. 2exe you need to create a setup. Distutils and py. Here's a setup. py whose simplicity is appropriate for our sample program.. Let's go through it line by line.. When working with py. 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 py. Whitespace is good! Call setup and tell it that we want a single console application and the main entry point is . Run your setup script. The next step is to run your setup script. Make sure to give the py. C: \Tutorial> python setup. C: \Tutorial\build\bdist. C: \Tutorial\build\bdist. C: \Tutorial\build\bdist. Python. 24\lib\String. IO. py to String. IO. pyc. . 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. Test your executable. Now that the package has been created it is ready to test: C: \Tutorial> cd dist. C: \Tutorial\dist> hello. Hello World. Excellent, it works!!! Providing the Microsoft Visual C runtime DLLThe Python interpreter was compiled using Microsoft Visual C, so your new program needs the Microsoft Visual C runtime DLL to run. If you have installed appropriate versions of Python or Visual Studio, then you will already have this DLL on your computer. If some of your users might not already have this DLL, then they will not be able to run your program. The methods you may use to solve this depend on the version of Python you are using: 5. Python 2. 4 or 2. If you are using Python 2. DLL you need is called MSVCR7. This DLL will probably already have been included in your dist directory, in which case you need do nothing more. However, the copyright on this file is owned by Microsoft, and you need to check whether you have the legal right to redistribute it. If you have a copy of Visual Studio, check the file redist. DLL. Generally you have the right to redistribute it if you own a license for Microsoft Visual C++, but not if you use the Express Editions. If you do not have the rights to redistribute MSVCR7. Microsoft Visual C++ 2. Redistributable Package (vcredist. Either you can instruct your users to download and run this themselves, or you could create an installer for your application (see Step 6 below), that includes vcredist. Python 2. 6, 2. 7, 3. For Python 2. 6, the DLL you need is called MSVCR9. Py. 2exe is not able to automatically include this DLL in your dist directory, so you must provide it yourself. To complicate things, there is more than one version of this DLL in existance, each with the same filename. You need the same version that the Python interpreter was compiled with, which is version 9. Through the remainder of these instructions, hover your mouse over the dll file (or the vcredist. You'll need the vcredist. As for older versions of Python, you need to check redist. Visual Studio installation to see whether you have the legal right to redistribute this DLL. If you do have these rights, then you have the option to bundle the C runtime DLL with you application. If you don't have the rights, then you must have your users run the redistributable C runtime installer on their machines. Bundling the C runtime DLLIf you do have the rights to redistribute MSVCR9. Visual Studio install, under VC\redist\x. Microsoft. VC9. 0. CRT. Since Visual Studio 2. DLL file - you also need the manifest file that you'll find there. Subject to the license terms for the software, you may redistribute the folder (unmodified) in the application local folder as a sub- folder with no change to the folder name. You may also redistribute all the files (*. To achieve this, add a data. Note that this method of including the C runtime is used by several Visual C++ applications - if you search your Program Files folder for msvcr. DLL and the associated manifest bundled alongside their executable like this. Also note that despite all the above, py. MSVCP9. 0. dll. Running the redistributable C runtime installer. If you don't have rights to redistribute MSVCR9. Microsoft Visual C++ 2. Redistributable Package (vcredist. It is important not to use the SP1 version of this installer, which contains the wrong version of MSVCR9. Either you can instruct your users to download and run this themselves, or you could create an installer for your application (see step 6 below), that includes vcredist. The installer puts a copy of the DLLs in the directory C: \WINDOWS\Win. Sx. S (XP), inside subdirectories with mangled names. The manifest file is in the 'Manifests' subdirectory, again this will have a mangled filename. You can still discern the text 'Microsoft. VC9. 0. CRT' and '9. It is possible to take a copy of these files and remove the filename mangling, to embed them in your application as described in 5. Build an installer if applicablepy. Python program. There are plenty of good installer builders out there including some that are open source (e. NSIS) and some that are free (e.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2017
Categories |