0

I have a Python module that can be run with both Python 2 and Python 3. At some point, the module takes a user input. How it does so depends on the Python major version:

  • Python 2: use raw_input
  • Python 3: use input

My IDE is PyCharm, and my project interpreter is Python 3.8. PyCharm inspects an unresolved reference error on raw_input.

Besides a # noinspection PyUnresolvedReferences tag, how can I get PyCharm not to complain about raw_input? Is there some setting I can enable?


Sample Code

#!/usr/bin/python


import sys


if sys.version_info[0] > 2:
    some_input = input("Please give input: ")
else:
    some_input = raw_input("Please give input: ")

print("input: {}".format(some_input))

What I see on my screen:

raw_input unresolved reference


Versions

  • Python: 3.8.2
  • PyCharm: CE 2019.3.1

My PyCharm has Code compatibility inspection enabled for Python 2.7, 3.6, 3.7, and 3.8.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119

1 Answers1

3

Environment checks are not supported in PyCharm, consider using input from six (https://six.readthedocs.io/#module-six.moves).

user2235698
  • 7,053
  • 1
  • 19
  • 27