unused import statement ... is wrong?

Sometimes PyCharm 3.0.1 marks an import statement (like 'import os') as unused, but if I comment it out, the program doesn't run, saying 'NameError: name 'os' is not defined'.

What might be happening?
Comment actions Permalink
Please, specify the case of using import.
Also you can suppress inspection: use "Alt+Enter" and go to Optimize import -> suppress for statement (take a look at web-help http://www.jetbrains.com/pycharm/webhelp/suppressing-inspections.html)
Comment actions Permalink
Ok, I've narrowed it down; it's something to do with a namespace collision, but it really shouldn't have this problem anyway, I think.

It's very common to do "from pylab import *" – I know that's Bad, but the thing is, this has never caused issues until PyCharm 3.0.1 for me. (And http://wiki.scipy.org/PyLab claims that this is the CORRECT way to import pylab.)

Here's a minimal program that shows the problem:

    import os
    from pylab import *

For that code, pycharm claims that "import os" is unused, but if you comment it out, os is not defined.
Comment actions Permalink

Having a similar issue, saying it's unused... Not sure what's going on. 


import org.joda.time.LocalTime;

public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
Comment actions Permalink

same here 

import numpy as xyz
np.random.seed (1)

NameError: name 'np' is not defined

Comment actions Permalink

Hi Thx2190,

You are creating an alias for numpy and call it xyz, but then you are trying to address it via np

The problem is not related to PyCharm.

You should either use import numpy as np instead of the first line of code or xyz.random.seed (1) instead of the second line of code.


Please sign in to leave a comment.