New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itools ImportError: cannot import name XMLError #242

Closed
bb-migration opened this Issue Aug 14, 2014 · 7 comments

Comments

Projects
None yet
1 participant
@bb-migration

bb-migration commented Aug 14, 2014

Originally reported by: Anonymous


Hi people,

Trying to install itools-0.75.1 spits out the following error

#!python

running install_egg_info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "setup.py", line 91, in <module>
    setup(ext_modules=ext_modules)
  File "pkg/utils.py", line 186, in setup
    ext_modules=ext_modules)
  File "/usr/local/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/install.py", line 61, in run
    return orig.install.run(self)
  File "/usr/local/lib/python2.7/distutils/command/install.py", line 575, in run
    self.run_command(cmd_name)
  File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 971, in run_command
    cmd_obj.ensure_finalized()
  File "/usr/local/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
    self.finalize_options()
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/install_egg_info.py", line 24, in finalize_options
    ei_cmd = self.get_finalized_command("egg_info")
  File "/usr/local/lib/python2.7/distutils/cmd.py", line 311, in get_finalized_command
    cmd_obj = self.distribution.get_command_obj(command, create)
  File "/usr/local/lib/python2.7/distutils/dist.py", line 845, in get_command_obj
    klass = self.get_command_class(command)
  File "/usr/local/lib/python2.7/site-packages/setuptools/dist.py", line 388, in get_command_class
    self.cmdclass[c==================================================================ommand] = cmdclass = ep.load()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources.py", line 2190, in load
    ['__name__'])
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 14, in <module>
    from setuptools.command.sdist import sdist
  File "/usr/local/lib/python2.7/site-packages/setuptools/command/sdist.py", line 9, in <module>
    from setuptools import svn_utils
  File "/usr/local/lib/python2.7/site-packages/setuptools/svn_utils.py", line 5, in <module>
    import xml.dom.pulldom
  File "xml/__init__.py", line 20, in <module>
    import dublin_core
  File "xml/dublin_core.py", line 21, in <module>
    from namespaces import XMLNamespace, register_namespace, ElementSchema
  File "xml/namespaces.py", line 24, in <module>
    from parser import XMLError
ImportError: cannot import name XMLError
*** Error code 1

The problem is that when installing itools with setuptools. It seems that setuptools does an "import xml" from itools directory and wrongly gets the xml itools.

According of the itools maintainer, the ideal fix would be that the module "svn_utils.py" from setuptools had an "import from future absolute_import".

Someone could take a look into this?

Regards,
--CJPM


@bb-migration

This comment has been minimized.

bb-migration commented Aug 14, 2014

Original comment by cjpm (Bitbucket: cjpm, GitHub: Unknown):


For more details, please, let me know.

--CJPM

@bb-migration

This comment has been minimized.

bb-migration commented Aug 14, 2014

Original comment by jdavidibp (Bitbucket: jdavidibp, GitHub: Unknown):


To reproduce the problem just type "pip install itools".

itools has a package named itools.xml, setuptols loads the module svn_utils.py which makes an "import xml" from the context of itools, which then imports itools.xml instead of the xml package from the standard library

The fix would be to use absolute imports in svn_utils.py

The fix in itools would be to rename itools.xml to something else, but that would break code using it. And anyway this is not really broken, as the absolute import itools.xml does not conflict with xml

Thanks!

@bb-migration

This comment has been minimized.

bb-migration commented Aug 14, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Use absolute_import in svn_utils. Fixes #242.

@bb-migration

This comment has been minimized.

bb-migration commented Aug 14, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


I don't believe this issue is strictly an issue with setuptools. I suspect there's an issue with itools where 'xml' is being put on the path. No package should be putting modules on the path that conflict with stdlib modules. Nevertheless, the suggested fix is suitable as setuptools only supports Python 2.6 and later, so that will go out as 5.6.

@bb-migration

This comment has been minimized.

bb-migration commented Aug 14, 2014

Original comment by jdavidibp (Bitbucket: jdavidibp, GitHub: Unknown):


Actually itools does not put "xml" in the import path. It is just that "import xml" is called from inside the itools directory, at least when installing with pip. Like if you did "cd itools" and then "import xml"

Anyway, thank you for fixing this so fast.

@bb-migration

This comment has been minimized.

bb-migration commented Aug 14, 2014

Original comment by jaraco (Bitbucket: jaraco, GitHub: jaraco):


Glad to help.

I took a quick look at the project sdist (as downloaded from PyPI or the web site). It does indeed put all of its subpackages in the root, alongside setup.py. There is no itools directory in the sdist, so xml (and all other modules) are present in '.' when setup.py is invoked. As a result, sys.path[0] will contain the xml module at the top level and not in 'itools' at the time setup.py is invoked. If you want to work around this issue for other versions of setuptools, you'll want to del sys.path[0] in setup.py or package the sdist differently.

@bb-migration

This comment has been minimized.

bb-migration commented Aug 18, 2014

Original comment by jdavidibp (Bitbucket: jdavidibp, GitHub: Unknown):


Finally I remade the packaging of itools and now it works with "older" versions of setuptools too. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment