Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing cross-compatible python2/python3 code in pycharm

Tags:

python

pycharm

I've taken care to make sure library works on both python2 and python3, but pycharm adds some vexatious red squiggles as seen below

enter image description here

If I switch the project interpreter to python 3.5 instead, the nag just moves onto the other import. Which inspection is this? I want to turn it off.

like image 217
wim Avatar asked Sep 14 '16 16:09

wim


1 Answers

Although it doesn't solve the issue for all cases, you can solve this particular problem by using the future package.

As you can see here, the future package provides its own version of builtins for python 2 and python 3. By relying on this package instead of doing it yourself, you can import future's implementation of builtins, thus removing the problematic code and avoiding Pycharm's (erroneous) error.

like image 111
Peter Brittain Avatar answered Sep 24 '22 00:09

Peter Brittain