How to distribute a usable python program to a python which doesn't have Distribute installed?

I've created a Windows Binary installer using python setup.py bdist_wininst. The setup.py contains a console script entry point, so that a Windows .exe file is created and placed in %python%\Scripts on the destination machine, as per Automatic Script Creation.

However running the installed script on a machine with a virgin python install yields:

D:\Py3.2.5> scripts\foo.exe
Traceback (most recent call last):
  File "D:\Py3.2.5\scripts\foo-script.py", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

No module named pkg_resources tells me this error is because Distribute is not installed.

How do I get my installer to include Distribute so I don't have to tell our users "before you install our program you have to go install this other program"?

有帮助吗?

解决方案

Ahh, finally found something:

Your users might not have setuptools installed on their machines, or even if they do, it might not be the right version. Fixing this is easy; just download distribute_setup.py, and put it in the same directory as your setup.py script. (Be sure to add it to your revision control system, too.) Then add these two lines to the very top of your setup script, before the script imports anything from setuptools:

import distribute_setup
distribute_setup.use_setuptools()

That’s it. The distribute_setup module will automatically download a matching version of setuptools from PyPI, if it isn’t present on the target system. Whenever you install an updated version of setuptools, you should also update your projects’ distribute_setup.py files, so that a matching version gets installed on the target machine(s).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top