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

Pylint doesn't find relative imports #795

Closed
fnkr opened this issue Jan 25, 2016 · 9 comments
Closed

Pylint doesn't find relative imports #795

fnkr opened this issue Jan 25, 2016 · 9 comments

Comments

@fnkr
Copy link

fnkr commented Jan 25, 2016

When using relative imports like

from ..user.models import User

I get these two errors:

  • No name 'user' in module 'models'
  • Unable to import 'user.models'
$ pylint --version
No config file found, using default configuration
pylint 1.5.4, 
astroid 1.4.4
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2]
@PCManticore
Copy link
Contributor

Can you give more details about this, what code did you use, how did you call pylint? I tried with a demo skeleton and it works just fine.

@fnkr
Copy link
Author

fnkr commented Jan 28, 2016

I just found out that it's a problem with my IDE, not with Pylint itself — I will report it there. Thanks for helping!

@fnkr fnkr closed this as completed Jan 28, 2016
@fnkr fnkr reopened this Feb 2, 2016
@fnkr
Copy link
Author

fnkr commented Feb 2, 2016

My IDE is running Pylint while the file is still unsaved, and for that reason, the IDE is copying the file into a temporary directory. That's the reason Pylint doesn't find the relative imports. Is there any parameter I could use, to tell Pylint the actual location of the file, or does Pylint support read from stdin?

@PCManticore
Copy link
Contributor

Hmm, no, pylint doesn't use the stdin for this, but I'm not sure there's anything we could do here if your files are in a temporary directory, which don't contain the respective imported modules.

@PCManticore
Copy link
Contributor

There's nothing we can do here, I'm afraid.

@Alexx-G
Copy link

Alexx-G commented Feb 11, 2016

Seems like an wrapper for pylint (linter-pylint) for the Atom (text editor) has the same issue.
I've described there AtomLinter/linter-pylint#110 some details.

The point is that it works in pylint<1.5.0.

@Alexx-G
Copy link

Alexx-G commented Feb 12, 2016

They have the following situation. To lint a file, they firstly copy it to a temporary directory.
After they insert into PYTHONPATH path to the package of original file and path of the project.
And run pylint over that temporary file.
I have the following layout:

/project
    /main_package
         /inner_package
             file.py
             file2.py

My PYTHONPATH contains /project:/project/main_package/inner_package and the command is something like this pylint /tmp/temporary-dir/file.py

The point is that according to this it should work. And it's working with pylint<1.5.0. But with with pylint 1.5+ I receive the error described above.

Update: and file.py contains from .file2 import something which causes import-error.

@PCManticore Could you help to figure out the problem and find a workaround to this? Maybe is something wrong with PYTHONPATH.

@horta
Copy link

horta commented Apr 21, 2016

I have exactly the same problem. The issue might come from the fact that:

  1. I'm using Anaconda python distribution;
  2. Anaconda documentation strongly suggests to not use PYTHONPATH (which I don't use): http://conda.pydata.org/docs/troubleshooting.html.

@horta
Copy link

horta commented Apr 23, 2016

I just pull requested a feature that would solve this issue: #881

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

4 participants