Sterbic
Sterbic

Reputation: 213

PyCharm Python 3.4 issue: unresolved reference

I have a problem with my PyCharm. After I updated Python from 3.3.5 to 3.4, I have an annoying error in PyCharm of the following form:

from multiprocessing import Queue, Process

PyCharm underlines Queue and Process in red and shows an unresolved reference. The code actually runs fine both in the command line and inside PyCharm. Code completion seems to be broken too for these classes.

I am suspecting a problem with PYTHONPATH, but I'm not sure how to solve it.

System details: Mac OS X 10.9.2, Python 3.4 installed through Homebrew, Pycharm 3.1.1

Upvotes: 7

Views: 5198

Answers (3)

Tung Nguyen
Tung Nguyen

Reputation: 1656

I have had the same issue. If you are using python 3.4.4, please try this:

from queue import Queue

You can read more here: https://docs.python.org/3.4/library/queue.html

Upvotes: 2

CrackerJack9
CrackerJack9

Reputation: 3651

I'd definitely report an issue with JetBrains if one doesn't already exist, but I would not suggest downgrading Python merely due to your IDE not interpreting an import as expected (the actual interpreter still works).

I have the same issue, simply adding # noinspection PyUnresolvedReferences above the unresolved references silences the compiler 'errors'. Of course I'd love this to be fixed and will remove the # noinspection lines once it is, but it certainly won't stop me from writing code using PyCharm and Python 3.4.

Edit: Looks like someone reported it: http://youtrack.jetbrains.com/issue/PY-12860

Edit: Reportedly fixed in build 138.913

Upvotes: 4

Jamie
Jamie

Reputation: 3931

It's not a problem with PYTHONPATH. If we look in multiprocessing\__init__.py, we see the following:

#
# Copy stuff from default context
#

globals().update((name, getattr(context._default_context, name))
                 for name in context._default_context.__all__)
__all__ = context._default_context.__all__

Notably there is nothing in the file that looks like Queue, Process, etc.

Now what is this context._default_context? If we look in multiprocessing\context.py, we see

class BaseContext(object):
    ...
    def Queue(self, maxsize=0):
        '''Returns a queue object'''
        from .queues import Queue
        return Queue(maxsize, ctx=self.get_context())

So in reality, Queue is never defined in the module itself, but rather through some dynamic code, it gets set correctly at runtime depending on the user's operating system. This is why Pycharm doesn't know that there are Queue and Process classes in the multiprocessing module.

Maybe you can file a bug report and try to get them to selectively run code to figure out these dynamic names or to make an exception here and put some workaround that tells Pycharm that there are in fact Queue/Process classes, but that seems like it would be low on their priority list. So you'll just have to live with it, probably. (In the same boat here)

Upvotes: 12

Related Questions