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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @user2235698! I found this answer also is related: stackoverflow.com/a/45321967/11163122

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.