Pycharm Professional saying "Cannot find reference '>>' in 'function'" when I use print >> in Python 2.7

166 Views Asked by At

I am using Pycharm to program something in Python 2.7 which runs in another application. I was using the Community edition but just switched to Professional. There are parts of the code where I use the "print >> " command. PyCharm Community was fine with this, but as soon as I switched to Professional it highlighted every single ">>" and put a line saying "Cannot find reference '>>' in 'function'" in the Problems tab for each one. The program still runs just fine but it's annoying, and turning off "Unresolved references" meant I missed some actual problems, so I turned it back on. Any way to fix this? I tried the invalidate cache and restart thing already. The interpreter being used is definitely Python 2.7.

It also complains when I am writing my unit tests and put a temporary statement like "print variable", it underlines the space between "print" and the variable in red and says "End of statement expected", but when I run the code (in PyCharm this time) it throws no errors and prints just fine. So PyCharm knows it's Python 2.7 but the inspector doesn't, I guess?

I also had similar issues with it highlighting every single function from gtk as an unresolved reference, but I was able to use one of the "quick fixes" to add those to the ignore list while that option doesn't come up for the "print >>" error.

I am expecting for the inspector to inspect the code for the syntax of the version of Python I'm actually using.

I've also tried right-clicking on every listed problem and saying "Suppress for a statement" but that puts a comment in my code which I don't want to be there and is time consuming. I've also tried to put things like "print >>" and ">>" in the "ignore" list for the unresolved references inspection but it doesn't seem to do anything.

Edit: I know it's been over a year, but after complaining to some friends, we seem to have found the source of the problem. So if you look at my name, you may notice it has an accented é in it. My user folder on my computer also has this accented é. I went through hell trying to get Python 2.7 to work at all because of this - it turns out it's hard-coded to use ascii encoding, and not only do I have to put # coding=utf-8 at the top of my files, I had to go into the Python 2.7 files themselves and change the encoding from ascii to utf-8.

A friend of mine tried to replicate the issues I was having - it didn't happen for them. Only difference was the changes I had to make to my Python to get it working despite my name. So while I didn't think it would be my name... apparently it is.

I doubt anyone will ever see this, but I figured I'd update just in case someone in the same situation ever comes across this on Google. It's your name again. Yeah, I hate that Python doesn't like non-English names too. Unfortunately you'll have to deal with it for Python to work. Sorry, man.

0

There are 0 best solutions below