This project has moved and is read-only. For the latest updates, please go here.

Cannot go to definition

Jan 21, 2014 at 7:42 PM
Hi, I am using a library installed in the site-packages folder. The script runs fine but when I right click on a function and want to see its definition, a window pops up saying "Cannot go to definition "XXX"". What could the issue be? Can you please help me to address this?
Jan 21, 2014 at 7:42 PM
BTW, I installed PTVS2.0 with VS2013 shell
Jan 21, 2014 at 7:50 PM
Can you tell us which library and function you are trying to go to? In general it should work, but there are some cases where it will not and you will see the error that you're getting.
Jan 21, 2014 at 7:51 PM
Can you tell a little bit more about what the library is, and how you installed it? Also, do you get code completion for the function in question, and quick tip when you hover over it?

One thing that might be an issue here is that if the library is packaged inside a .zip or .egg file, and you placed that file in site-packages as is, then PTVS won't be able to show source code directly from it.
Jan 21, 2014 at 8:57 PM
Thanks a lot for your reply!

I am using a library called IMUSim, which is not widely used. It is installed under the path:


with two folders inside:


I noticed this is different from most other installed libraries.

At the beginning of the script, I wrote:

from imusim.all import *

to import everything I need. But when I hover over a function, e.g. Simulation(), the label says: Simulation: <unknown type>
If I click on the function, there will be a little button under the function name. If I select on that, it asks me to select a more detailed import source.
If I select one, e.g. "from imusim.simulation.base import Simulation", now it can find the definition.

The code in in "all" folder is:

import pkgutil
import os
import inspect

all = []
path = os.path.split(pkgutil.get_loader('imusim').filename)[0]
for loader, modname, ispkg in pkgutil.walk_packages([path]):
if modname.startswith('imusim') \
        and not modname.startswith('imusim.tests') \
        and not modname.startswith('imusim.all'):
    exec("import %s" % modname)
    exec("module = %s" % modname)
    symbols = filter(lambda o: not inspect.ismodule(o),
            module.__all__ if hasattr(module,'__all__') else dir(module))
    symbols = filter(lambda s: not s.startswith('_'), symbols)
    exec("from %s import *" % modname)
    __all__ += symbols
What should I do in this case?
Jan 23, 2014 at 3:10 PM
Is this due to the incorrect way of installing the package? What can I do to address this issue?
Jan 23, 2014 at 5:12 PM
No, this is because the package is not defined until runtime. We don't execute any code while determining what members are defined in a package (in case that code happens to be shutil.rmtree("C:\\")), and so it looks like is empty.

Looking at the code that they're using, there's no way we could reliably handle this. They really should be importing all of the members directly with hand-coded (or generated) from ... import ... statements. I would suggest reporting it to them as a bug. There are enough Python IDEs around these days and I'd be surprised if any of them handled this approach (and if they do, they'll probably also wipe your harddrive if the script says to).