background preloader

Packaging and distribution

Facebook Twitter

PyInstaller. Tutorial - py2exe.org. Py2exe turns Python programs into packages that can be run on other Windows computers without needing to install Python on those computers. You must run py2exe on a Windows computer. 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. Install py2exe on your Windows computer using pip: pip install py2exe There are a few simple steps needed to use py2exe once you've installed it: 1. The biggest step is almost always the first one. It's important that you make sure everything is working before you use py2exe. The first example we'll use here is our old friend... hello.py We need to make sure it's working... C:\Tutorial>python hello.py Hello World! Looks good! 2. Setup.py 3. 4. 5. The ExeMaker Tool. Updated October 12, 2004 | October 10, 2004 | Fredrik Lundh “Outstanding utility.

It isn’t just neat, it’s indispensable. ” ExeMaker is a small tool that takes a Python script, copies it to a program directory, and creates a Windows EXE file in the same directory. When you run that EXE, it automatically runs the script. To see how it works, let’s look at an example: > exemaker pythondoc.py c:/bin c:/bin/pythondoc.exe ok c:/bin/pythondoc.py ok > dir c:\bin\pythondoc* 2004-10-10 15:00 4 096 pythondoc.exe 2004-10-10 15:00 41 611 pythondoc.py 2 File(s) 45 707 bytes Assuming that c:/bin is on your path, you can now run the script as a normal command-line tool: > pythondoc PythonDoc 2.1b3 (c) 2002-2003 by Fredrik Lundh.

In other words, ExeMaker lets you install command-line programs written in Python along with other utilities, and use them without having to bother with PY associations, BAT files, or other workarounds. Usage Syntax: exemaker [-i interpreter] script [directory] Details #! The #! Setuptools - The PEAK Developers' Center. Basic Use For basic use of setuptools, just import things from setuptools instead of the distutils. Here's a minimal setup script using setuptools: from setuptools import setup, find_packages setup( name = "HelloWorld", version = "0.1", packages = find_packages(), ) As you can see, it doesn't take much to use setuptools in a project. Just by doing the above, this project will be able to produce eggs, upload to PyPI, and automatically include all packages in the directory where the setup.py lives.

Of course, before you release your project to PyPI, you'll want to add a bit more information to your setup script to help people find or learn about your project. In the sections that follow, we'll explain what most of these setup() arguments do (except for the metadata ones), and the various ways you might use them in your own project(s). Specifying Your Project's Version A version consists of an alternating series of release numbers and pre-release or post-release tags. Automatic Script Creation. Welcome to Distribute’s documentation! — Distribute documentation.

Installing the Package Tools — The Hitchhiker's Guide to Packaging v1.0 documentation. In the current state of packaging in Python, one needs a set of tools to easily manipulate the packaging ecosystem. There are two tools in particular that are extremely handy in the current ecosystem. There is a third tool, Virtual Environments, that will be discussed later in this documentation that will assist in isolating a packaging ecosystem from the global one. The combination of these tools will help to find, install and uninstall packages.

Distribute Distribute is a collection of enhancements to the Python standard library module: distutils (for Python 2.3.5 and up on most platforms; 64-bit platforms require a minimum of Python 2.4) that allows you to more easily build and distribute Python packages, especially ones that have dependencies on other packages. Distribute was created because the Setuptools package is no longer maintained. Installation Instructions Distribute can be installed using the distribute_setup.py script. From the *nix shell you can do: Note Installing Pip. EasyInstall - The PEAK Developers' Center. Installing "Easy Install" Please see the setuptools PyPI page for download links and basic installation instructions for each of the supported platforms. You will need at least Python 2.3.5, or if you are on a 64-bit platform, Python 2.4. An easy_install script will be installed in the normal location for Python scripts on your platform.

Note that the instructions on the setuptools PyPI page assume that you are are installling to Python's primary site-packages directory. If this is not the case, you should consult the section below on Custom Installation Locations before installing. (And, on Windows, you should not use the .exe installer when installing to an alternate location.) Note that easy_install normally works by downloading files from the internet. Troubleshooting Windows Notes On Windows, an easy_install.exe launcher will also be installed, so that you can just type easy_install as long as it's on your PATH.

Downloading and Installing a Package Example 1. Easy_install SQLObject. Virtual Environments — The Hitchhiker's Guide to Packaging v1.0 documentation. Creating a virtualenv We’ll be using virtualenv so our installation experiments are contained and don’t modify your system Python environment. If you aren’t already familiar with virtualenv, you may want to read up on it first. Create a virtualenv: $ virtualenv --no-site-packages pip_test_env We use the --no-site-packages flag to prevent this virtualenv from “seeing” your global Python “site-packages” directory, so that our experiments aren’t confused by any Python packages you happen to already have installed globally.

Recent versions of virtualenv (1.4+) automatically install pip for you inside the virtualenv (there will already be a pip script in pip_test_env/bin/). Note If you are using Windows, executable scripts in the virtualenv will be located at pip_test_env\Scripts\ rather than pip_test_env/bin/. Let’s “activate” the virtualenv to put pip_test_env/bin on our default PATH, so we can just type pip instead of pip_test_env/bin/pip: $ . pip_test_env/bin/activate On Windows, this is: Pip — pip 1.1.post1 documentation. Python eggs. Requirements for `account number` generator: Issue pseudo random consistent number (must be unique for dozen millions of records)Easy check validity (without a need to make a database call) We will use Feistel cipher to generate pseudo random number (positive only) from a sequential numbers (e.g. returned by nextval() for a posgresql sequence).

This algorithm is taken as basis for the `make_feistel_number` function available in wheezy.core package. Setup environment before proceed: $ virtualenv env $ env/bin/easy_install wheezy.core $ env/bin/python Let play a bit how numbers are generated (notice, the function is reversal and consistent, all numbers are unique, no collision): >>> from wheezy.core.feistel import make_feistel_number >>> from wheezy.core.feistel import sample_f >>> feistel_number = make_feistel_number(sample_f)>>> feistel_number(1)573852158>>> feistel_number(2)1788827948>>> feistel_number(1788827948)2 We will use Luhn algorithm to generate a single digit checksum.

Working With Packages in Python. Using pip to Manage Python Packages Like many useful programming ecosystems, Python provides a powerful and easy-to-use package management system called pip. It is written to replace an older tool called easy_install. From a high-level point of view, pip has the following advantages over easy_install: All packages are downloaded before installation to prevent partial (thus broken) installation.Output information is pre-processed, so it's more useful than eccentric messages.It keeps record of why actions are performed.

For example, the reason why a package was required is recorded for future reference.Packages can be installed as flat modules, which makes library-code debugging much easier than egg archives.Native support for other version control systems. For example, you could install a Python package directly from a GitHub repository if it's setup properly.Packages can be uninstalled. Setting up virtualenv and pip to perform simple operations Adding/installing Packages with pip 1. 2. Distributing Python Modules — Python v2.7. Packaging Python Libraries - Dive Into Python 3. You are here: Home ‣ Dive Into Python 3 ‣ Difficulty level: ♦♦♦♦♢ ❝ You’ll find the shame is like the pain; you only feel it once. ❞— Marquise de Merteuil, Dangerous Liaisons Diving In# So you want to release a Python script, library, framework, or application. Excellent. The world needs more Python code. Python 3 comes with a packaging framework called Distutils. All of these facets of Distutils center around the setup script, traditionally called setup.py.

In this chapter, you’ll learn how the setup scripts for chardet and httplib2 work, and you’ll step through the process of releasing your own Python software. skip over this code listing This version requires Python 3 or later; a Python 2 version is available separately. """) ☞chardet and httplib2 are open source, but there’s no requirement that you release your own Python libraries under any particular license. Things Distutils Can’t Do For You# Releasing your first Python package is a daunting process. Choose a license. Directory Structure#