Using Scripts\foo.exe on a python which doesn't have Distribute installed?
Hi folks, *I've been up one side of the internet and down the other, and haven't seen this question discussed before, but as has often been the case perhaps it's just my search-fu which is weak, in which case, please kindly direct me to the answer or documentation where I can find it. Thanks :)* 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 Creationhttp://pythonhosted.org/distribute/setuptools.html#automatic-script-creation . However running the installed script on a machine with a virgin python install yields: D:\Py3.2.5> scripts\foo.exeTraceback (most recent call last): File "D:\Py3.2.5\scripts\foo-script.py", line 5, in <module> from pkg_resources import load_entry_pointImportError: No module named pkg_resources No module named pkg_resourceshttp://stackoverflow.com/questions/7446187/no-module-named-pkg-resourcestells me this error is because Distribute http://pythonhosted.org/distribute/index.html 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"*? thanks in advance for your time, -matt
On Wed, May 22, 2013 at 8:12 PM, Matt Wilkie
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"?
Setuptools (which Distribute is based on) is designed for shipping libraries, not applications; it's developer installer, not primarily an end-user installer for applications. So you probably should be using py2exe instead. Alternatively, you can bundle a copy of pkg_resources.py, or use a script that doesn't depend on entry points, or copy your script to "foo-script.py" alongside the .exe launcher, and manually include those two files as scripts (not using entry points) in your setup() definition. Any of these approaches will solve the problem; it's mostly a matter of your preferences or other requirements.
Thanks PJ.
I haven't used py2exe as I don't want to redistribute python also,
just our program. I'll dig into your other suggestions and see where I
end up.
-matt
On Wed, May 22, 2013 at 10:22 PM, PJ Eby
On Wed, May 22, 2013 at 8:12 PM, Matt Wilkie
wrote: 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"?
Setuptools (which Distribute is based on) is designed for shipping libraries, not applications; it's developer installer, not primarily an end-user installer for applications. So you probably should be using py2exe instead.
Alternatively, you can bundle a copy of pkg_resources.py, or use a script that doesn't depend on entry points, or copy your script to "foo-script.py" alongside the .exe launcher, and manually include those two files as scripts (not using entry points) in your setup() definition.
Any of these approaches will solve the problem; it's mostly a matter of your preferences or other requirements.
slapped reply too early, sorry.
Alternatively, you can bundle a copy of pkg_resources.py,
I managed to get this to work by adding it as a script in setup.py:
#smelly hack, allows foo.exe to run on machines w/out Distribute
scripts = [
'setup/pkg_resources.py',
],
this puts it in "PythonXX\Scripts" on the target machine, as I'm sure you know.
What happens if the target machine already has Distribute or
Setuptools installed, and thus has pkg_resources somewhere under
"PythonXX\Lib\site-packages", and likely a different version to boot?
I tried putting it in the same tree as our stuff,
"foo/external/pkg_resources.py", but that's not found. I'm assuming
because it thinks it's name is "foo.external.pkg_resources".
-matt
On Sat, May 25, 2013 at 12:46 AM, Matt Wilkie
Thanks PJ.
I haven't used py2exe as I don't want to redistribute python also, just our program. I'll dig into your other suggestions and see where I end up.
-matt
Hi Matt, if you don't have any C extensions to deal with and can
assume Python is already present on the destination system, then a
zipfile with a __main__.py file may also be a suitable solution (see
PEP 441 for more info about that feature - it's been supported since
2.6, the PEP just proposes some better tools in the standard library
for creating them)
Cheers,
Nick.
On Sat, May 25, 2013 at 5:46 PM, Matt Wilkie
Thanks PJ.
I haven't used py2exe as I don't want to redistribute python also, just our program. I'll dig into your other suggestions and see where I end up.
-matt
On Wed, May 22, 2013 at 10:22 PM, PJ Eby
wrote: On Wed, May 22, 2013 at 8:12 PM, Matt Wilkie
wrote: 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"?
Setuptools (which Distribute is based on) is designed for shipping libraries, not applications; it's developer installer, not primarily an end-user installer for applications. So you probably should be using py2exe instead.
Alternatively, you can bundle a copy of pkg_resources.py, or use a script that doesn't depend on entry points, or copy your script to "foo-script.py" alongside the .exe launcher, and manually include those two files as scripts (not using entry points) in your setup() definition.
Any of these approaches will solve the problem; it's mostly a matter of your preferences or other requirements.
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
That looks very interesting Nick!
Do you know of any small or smallish programs using this I could
inspect and learn from? Most of the references I find surround
pyinstaller it's specfile format.
thanks,
-matt
On Sat, May 25, 2013 at 1:02 AM, Nick Coghlan
Hi Matt, if you don't have any C extensions to deal with and can assume Python is already present on the destination system, then a zipfile with a __main__.py file may also be a suitable solution (see PEP 441 for more info about that feature - it's been supported since 2.6, the PEP just proposes some better tools in the standard library for creating them)
Cheers, Nick.
On Sat, May 25, 2013 at 5:46 PM, Matt Wilkie
wrote: Thanks PJ.
I haven't used py2exe as I don't want to redistribute python also, just our program. I'll dig into your other suggestions and see where I end up.
-matt
On Wed, May 22, 2013 at 10:22 PM, PJ Eby
wrote: On Wed, May 22, 2013 at 8:12 PM, Matt Wilkie
wrote: 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"?
Setuptools (which Distribute is based on) is designed for shipping libraries, not applications; it's developer installer, not primarily an end-user installer for applications. So you probably should be using py2exe instead.
Alternatively, you can bundle a copy of pkg_resources.py, or use a script that doesn't depend on entry points, or copy your script to "foo-script.py" alongside the .exe launcher, and manually include those two files as scripts (not using entry points) in your setup() definition.
Any of these approaches will solve the problem; it's mostly a matter of your preferences or other requirements.
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
On Sat, May 25, 2013 at 6:16 PM, Matt Wilkie
That looks very interesting Nick!
Do you know of any small or smallish programs using this I could inspect and learn from? Most of the references I find surround pyinstaller it's specfile format.
The zipfile execution feature was added primarily as a tool for internal distribution within large Python-using organisations, so I'm not aware of any good examples on the public internet (I assume it's seeing some use inside Google, as that's where the idea originated). Internet distribution tends to use either py2exe and its ilk (because the distributor can't assume a Python interpreter on the destination system) or else give users instructions on installing and using pip or easy_install (because they want their instructions to work across at least the main three platforms). Using pip or easy_install to do the installation also has the side effect of getting pkg_resources onto the target system, since some features of that ecosystem (like entry points) require it. Being able to assume the presence of Python on the target system but *not* the presence of pkg_resources is a fairly idiosyncratic case, which is why you haven't been able to find much specific info on handling it. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
Being able to assume the presence of Python on the target system but *not* the presence of pkg_resources is a fairly idiosyncratic case, which is why you haven't been able to find much specific info on handling it.
This might be a Windows thing. I'm coming primarily from that background, where for most "if it doesn't have a GUI installer, it doesn't exist", and Distribute doesn't have an installer. I guess it's idiosyncratic because those coming before me on a similar path would have just gravitated to NSIS or similar for this need. -matt
On Sat, May 25, 2013 at 4:16 PM, Matt Wilkie
That looks very interesting Nick!
Do you know of any small or smallish programs using this I could inspect and learn from? Most of the references I find surround pyinstaller it's specfile format.
This article explain about using the __main__.py file - http://sayspy.blogspot.com/2010/03/various-ways-of-distributing-python.html As for example, one that I recently found - https://github.com/pagekite/PyPagekite/
... or use a script that doesn't depend on entry points
not desirable, as we like the .exe entry points creates and don't want to use a batch file (the "are you sure you want to quit?" message on ctrl-c is annoying)
, or copy your script to "foo-script.py" alongside the .exe launcher, and manually include those two files as scripts (not using entry points) in your setup() definition.
Would you please expand on this? The .exe launcher seems to depend on entry points, or I'm doing something wrong (entirely likely). thanks, -matt
On Sat, May 25, 2013 at 4:06 AM, Matt Wilkie
... or use a script that doesn't depend on entry points
not desirable, as we like the .exe entry points creates and don't want to use a batch file (the "are you sure you want to quit?" message on ctrl-c is annoying)
, or copy your script to "foo-script.py" alongside the .exe launcher, and manually include those two files as scripts (not using entry points) in your setup() definition.
Would you please expand on this? The .exe launcher seems to depend on entry points, or I'm doing something wrong (entirely likely).
The foo.exe launcher doesn't use the entry point, all it does is run an adjacent foo-script.py. You can put anything you want in foo-script.py adjacent to that .exe, and it'll run. As for different versions of pkg_resources on sys.path, Python always puts the directory containing the script first. So if there's a pkg_resources.py adjacent to the script, that will take precedence over any other copy.
The foo.exe launcher doesn't use the entry point, all it does is run an adjacent foo-script.py. You can put anything you want in foo-script.py adjacent to that .exe, and it'll run.
Ahhh, perfect! I've verified it works for me, and much better than bundling a duplicate of Distribute. Thanks! [...later]: is a postinstall the best (only?) means to replace the contents of foo-script.py? By experimentation I've learned the `entry_points=` script supersedes a `scripts=` script of the same name.
As for different versions of pkg_resources on sys.path, Python always puts the directory containing the script first. So if there's a pkg_resources.py adjacent to the script, that will take precedence over any other copy.
Thanks, this is good to know. best, -matt
participants (4)
-
Matt Wilkie
-
Mohd Kamal Bin Mustafa
-
Nick Coghlan
-
PJ Eby