Skip to content
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

importing cElementTree fails with PTVS #756

Closed
blelem opened this issue Aug 14, 2015 · 2 comments
Closed

importing cElementTree fails with PTVS #756

blelem opened this issue Aug 14, 2015 · 2 comments

Comments

@blelem
Copy link

blelem commented Aug 14, 2015

Hi,
This may well not be a PTVS error, but I can't figure out what else it could be.

When executing my Django project from VS from visual studio 15, the command

 from xml.etree import cElementTree

throws an exception. This is discussed here: https://pytools.codeplex.com/workitem/2077. Based on the number of upvotes and the related discussion, this seems to be pretty easy to reproduce and not specific to my project. I understand that PTVS can't figure out that the exception is actually caught down the road and signals it to the user. That's ok.

The thing is that

     from xml.etree import cElementTree 

should not leave in the first place! cElementTree is part of the standard Python distro and it's definitely available in my environment. (I'm on python 2.7)

You will find here a simple bottle project to reproduce. It's just the bottle template, where I added the import commands in the file routes.py.
If the import is called from the global context (line 10 of routes.py), it will throw.
If I delay the import to a later phase, for example moving it inside the function home(), line 15 of routes.py, the import will be successful.

     def home():
        """Renders the home page."""
        # Loading cElementTree succeeds, if called here.
        from xml.etree import cElementTree 

Would it be possible that PTVS or the VS debugger would interfere with the import process if the cElementtree is imported early when the project is launched?

cElementtree represents a significant performance boost versus it's pure Python sibling, would be nice to be able to use it in a PTVS environment.

@int19h
Copy link
Contributor

int19h commented Aug 14, 2015

The exception is raised as part of the import. It does not cause the import to fail, because it is also caught as part of the import. PTVS is not really interfering with the process here, it's just (improperly) reporting an exception that normally occurs under the hood. If you tell it to continue running once it has reported it, it should complete the import successfully.

@blelem
Copy link
Author

blelem commented Aug 15, 2015

That's right, the import works : the leave is internal. I have no problems using cElementTree.
Thanks for the quick answer!

@blelem blelem closed this as completed Aug 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants