Re: [Distutils] Help with easy_install
Phillip J. Eby
From reading your setup script, I don't understand why your package needs a .pth file of its own, let alone why it's writing it directly in the setup script. I would expect it to work correctly if you simply delete that portion of the setup script. In fact, it works for me that way.
Without the .pth file, the libraries in the folder pyspread are not found. If I leave it out, the program fails to start (after installation finished successfully).
One other thing you need to change if you want easy_install to handle dependencies:
requires=['numpy (>=1.1)', 'wx (>=2.7)'],
Either change this line (or add another) saying:
install_requires=["numpy>=1.1", "wx>=2.7"],
This does not work at all for me. I do have all dependencies met (I am installing everything else via apt) but easy_install does not recognize it and throws a DistributionNotFound: wx>=2.7 *after* installation.
Also note that this line is superfluous (neither distutils nor setuptools need it):
package_dir={'pyspread': 'pyspread'},
I have removed that sucessfully.
And of course, delete the entire block below; as far as I can tell, it's not needed for distutils or setuptools.
import distutils.sysconfig try: pthfile = open(get_python_lib() + "/pyspread.pth", 'w') pthfile.write("pyspread") pthfile.close() except IOError: print 'Creation of ' + distutils.sysconfig.get_python_lib() + ' pyspread.pth failed.'
And how do I get the pyspread.pth file created? Best Regards Martin
Martin Manns wrote:
Phillip J. Eby
wrote: From reading your setup script, I don't understand why your package needs a .pth file of its own, let alone why it's writing it directly in the setup script. I would expect it to work correctly if you simply delete that portion of the setup script. In fact, it works for me that way.
Without the .pth file, the libraries in the folder pyspread are not found. If I leave it out, the program fails to start (after installation finished successfully).
Rename pyspread.py to something else, then use package imports. E.g. from pyspread import _widgets from pyspread._choicebars import MainMenu, MainToolbar from pyspread._dialogs import MacroDialog, CsvImportDialog, DimensionsEntryDialog, \ AboutDialog from pyspread._interfaces import CsvImport, string_match from pyspread.config import DEBUG, LIBPREFIX, ICONPREFIX, icon_size -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
At 09:24 AM 12/1/2008 +0000, Martin Manns wrote:
Phillip J. Eby
wrote: From reading your setup script, I don't understand why your package needs a .pth file of its own, let alone why it's writing it directly in the setup script. I would expect it to work correctly if you simply delete that portion of the setup script. In fact, it works for me that way.
Without the .pth file, the libraries in the folder pyspread are not found. If I leave it out, the program fails to start (after installation finished successfully).
You'll need to be more specific about what "fails to start" means. What specifically happens? What is the traceback?
One other thing you need to change if you want easy_install to handle dependencies:
requires=['numpy (>=1.1)', 'wx (>=2.7)'],
Either change this line (or add another) saying:
install_requires=["numpy>=1.1", "wx>=2.7"],
This does not work at all for me. I do have all dependencies met (I am installing everything else via apt) but easy_install does not recognize it and throws a DistributionNotFound: wx>=2.7 *after* installation.
Ah. Well, in that case, I guess you can leave wx out of it. I forgot that wx doesn't have egg support yet.
And of course, delete the entire block below; as far as I can tell, it's not needed for distutils or setuptools.
import distutils.sysconfig try: pthfile = open(get_python_lib() + "/pyspread.pth", 'w') pthfile.write("pyspread") pthfile.close() except IOError: print 'Creation of ' + distutils.sysconfig.get_python_lib() + ' pyspread.pth failed.'
And how do I get the pyspread.pth file created?
You don't. If your program isn't working without it, it probably means your program isn't doing its imports correctly. Offhand, my guess is that you're using pyspread.pyspread as a main program, and also trying to import things from the pyspread package. That won't work correctly, because Python puts the directory containing the __main__ script as the first entry on sys.path -- meaning that when you try to import from the pyspread *package*, you instead wind up importing from the pyspread *script*. But let's see your traceback to find out what's really going on.
On Dec 1, 2008, at 10:47 AM, Phillip J. Eby wrote:
Ah. Well, in that case, I guess you can leave wx out of it. I forgot that wx doesn't have egg support yet.
At least last February, the wx people were waiting for setuptools to provide a way to do post-install hooks: http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss: 73095:200802:hndcapodnmpbdhbnmgpn On the other hand the Enthought folks seem to have gotten pretty far without that, two years ago: https://svn.enthought.com/enthought/ticket/1178 Regards, Zooko
zooko wrote:
On Dec 1, 2008, at 10:47 AM, Phillip J. Eby wrote:
Ah. Well, in that case, I guess you can leave wx out of it. I forgot that wx doesn't have egg support yet.
At least last February, the wx people were waiting for setuptools to provide a way to do post-install hooks:
http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss:73095:200802:hndcapodnmp...
On the other hand the Enthought folks seem to have gotten pretty far without that, two years ago:
Actually, at Enthought we have eggs on several different platforms, but they do require post-install scripts. -- Chris Galvan
Regards,
Zooko _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig
Phillip J. Eby
At 09:24 AM 12/1/2008 +0000, Martin Manns wrote:
Phillip J. Eby
wrote: From reading your setup script, I don't understand why your package needs a .pth file of its own, let alone why it's writing it directly in the setup script. I would expect it to work correctly if you simply delete that portion of the setup script. In fact, it works for me that way.
Without the .pth file, the libraries in the folder pyspread are not found. If I leave it out, the program fails to start (after installation finished successfully).
You'll need to be more specific about what "fails to start" means. What specifically happens? What is the traceback?
OK I removed all files manually including the egg, removed the wx requirement from setup.py and installed again: $ cat setup.py #!/usr/bin/env python from distutils.core import setup from distutils.sysconfig import get_python_lib setup(name='pyspread', version='0.0.10b', description='A spreadsheet that accepts a pure python expression in each cell.', license='GPL v3 :: GNU General Public License', classifiers=[ 'Development Status :: 3 - Alpha', 'Intended Audience :: End Users/Desktop', ], author='Martin Manns', author_email='mmanns@gmx.net', url='http://sourceforge.net/projects/pyspread/', install_requires=["numpy>=1.1"], requires=['numpy (>=1.1)'], scripts=['pyspread/pyspread.py'], packages=['pyspread'], package_data={'pyspread': ['icons/*.png', 'icons/actions/*.png', \ 'examples/*', \ 'doc/manual.html', 'README', 'COPYING']}, ) $ su # easy_install-2.5 pyspread-0.0.10b.zip Processing pyspread-0.0.10b.zip Running pyspread-0.0.10b/setup.py -q bdist_egg --dist-dir /tmp/easy_install-bI0ZtQ/pyspread-0.0.10b/egg-dist-tmp-VNtCCf zip_safe flag not set; analyzing archive contents... Adding pyspread 0.0.10b to easy-install.pth file Installing pyspread.py script to /usr/bin Installed /usr/lib/python2.5/site-packages/pyspread-0.0.10b-py2.5.egg Processing dependencies for pyspread==0.0.10b Finished processing dependencies for pyspread==0.0.10b # exit $ pyspread.py Traceback (most recent call last): File "/usr/bin/pyspread.py", line 5, in <module> pkg_resources.run_script('pyspread==0.0.10b', 'pyspread.py') File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 448, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 1173, in run_script exec script_code in namespace, namespace File "/usr/bin/pyspread.py", line 65, in <module> ImportError: No module named _widgets And indeed there is no sub-folder pyspread in site-packages and therefore no module _widgets that can be found.
And how do I get the pyspread.pth file created?
You don't. If your program isn't working without it, it probably means your program isn't doing its imports correctly.
Offhand, my guess is that you're using pyspread.pyspread as a main program, and also trying to import things from the pyspread package. That won't work correctly, because Python puts the directory containing the __main__ script as the first entry on sys.path -- meaning that when you try to import from the pyspread *package*, you instead wind up importing from the pyspread *script*. But let's see your traceback to find out what's really going on.
Hmm. Not quite, I guess. My idea of the directory structure is as follows: + Everything but the main script that is in /usr/bin resides in [...]/site-packages/pyspread + The modules are imported directly (without pyspread.[mymodule] Probably this is a bad idea. However, with the pyspread.pth file in site-packages, it works. I just made a deb that has all files in an own directory in /usr/lib/pyspread and the images etc. in /usr/share/pyspread Perhaps, this can be done with easy_install, too. Martin
At 08:58 PM 12/1/2008 +0000, Martin Manns wrote:
And indeed there is no sub-folder pyspread in site-packages and therefore no module _widgets that can be found.
That's got nothing to do with the import error. The import error is because of the sys.path issue that I described in my previous email:
Offhand, my guess is that you're using pyspread.pyspread as a main program, and also trying to import things from the pyspread package. That won't work correctly, because Python puts the directory containing the __main__ script as the first entry on sys.path -- meaning that when you try to import from the pyspread *package*, you instead wind up importing from the pyspread *script*.
...
My idea of the directory structure is as follows: + Everything but the main script that is in /usr/bin resides in [...]/site-packages/pyspread + The modules are imported directly (without pyspread.[mymodule] Probably this is a bad idea.
It's a *very* bad idea -- and not because of the distutils or setuptools, either. For one thing, you can end up with two copies of the same module in sys.modules under different names, i.e. both as '_foo' and 'pyspread._foo', and then you can end up with duplicate classes, making isinstance() tests fail (among other potential oddities). IOW, putting a __main__ script inside a package is bad juju where Python is concerned. Also naming that __main__ script the *same name as the package* then borders on insanity. ;-) That's why Robert Kern was saying you need to rename pyspread.py to something else, and then use package imports only. That will keep you from running afoul of the duplication problem.
However, with the pyspread.pth file in site-packages, it works.
Yeah, that's just hiding the problem, it's not really fixing it. Also, it's in very bad taste for a setup.py script to unconditionally write files; as it stands, somebody running "setup.py --help" will get a .pth file installed... and NOT to their configured --install-lib, either! (i.e., it may write to somewhere *other* than where they told the distutils to install the package).
I just made a deb that has all files in an own directory in /usr/lib/pyspread and the images etc. in /usr/share/pyspread Perhaps, this can be done with easy_install, too.
Ah, here's where your problem is. Instead of using get_python_lib() to find the default package directory, i.e.: LIBPREFIX = distutils.sysconfig.get_python_lib() + '/pyspread/' ICONPREFIX = distutils.sysconfig.get_python_lib() + '/pyspread/' Do this instead: import os.path LIBPREFIX = ICONPREFIX = os.path.dirname(__file__) This will work with both distutils and setuptools, including cases where somebody installs your program someplace other than the system-wide site-packages directory. (E.g. using "setup.py install --install-lib=~/pylib") Also, by using __file__, setuptools will be able to notice that you're accessing your own package contents directly, and will install your package unzipped. In short, all of these changes will only improve your results and packaging, whether your users are using distutils or setuptools to install it.
Phillip J. Eby
Ah, here's where your problem is. Instead of using get_python_lib() to find the default package directory, i.e.:
LIBPREFIX = distutils.sysconfig.get_python_lib() + '/pyspread/' ICONPREFIX = distutils.sysconfig.get_python_lib() + '/pyspread/'
Do this instead:
import os.path LIBPREFIX = ICONPREFIX = os.path.dirname(__file__)
This works great. Thank you for all your help (also to Robert Kern). Best Regards Martin
participants (5)
-
Chris Galvan
-
Martin Manns
-
Phillip J. Eby
-
Robert Kern
-
zooko