Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to suppress unresolved imports in eclipse in a PyDev project?

I have a Python project in eclipse, which imports modules that can't be found by Python. Here's a list of some of the cases:

  1. some of the files might import both the 2.x and 3.x versions of some built-in modules for compatibility purposes (but I can specify only one grammar version in the project's settings)

  2. since the scripts I'm writing will be ran in an environment very different from mine, some of the modules I use don't even exist in the system (like Windows-specific modules, or modules from other projects that I REALLY don't want to link directly to this one)

  3. modules that might or might not be installed on the machine where the script is going to be executed (of course, wrapped into try-except clauses) and so on...

It is very annoying to have these modules marked as errors, since they make REAL syntax errors much less noticeable. I know that this behavior can somehow be overridden - I have another project that doesn't mark unresolved imports as errors, but I just can't find the right setting for it. Can anyone help me?

like image 566
Grisha S Avatar asked Apr 22 '13 06:04

Grisha S


1 Answers

How about adding #@UnresolvedImport to your imports? Eg:

import a_module_pydev_doesnt_know #@UnresolvedImport

You can simply press Ctrl-1 when your cursor is placed in a line where PyDev marked an error and and select the corresponding entry to automatically add it.

Edit: I don't have much experience with it, but it seems that if you want to change this for a whole project (or do it without touching your code), you can also add the module in question to the forced built-ins: http://pydev.org/manual_101_interpreter.html#PyDevInterpreterConfiguration-ForcedBuiltins

like image 100
rainer Avatar answered Sep 29 '22 01:09

rainer