pyCharm writes "python version 2.7 doesn't have module pathlib" while project interpreter is set to 3.5.2. (mac os high sierra)

Answered

Hello.
I need to import module pathlib, but pyCharm somewhy writes about python 2.7 doesn't have this module.
I know python 2.7 is the default interpreter for mac, that's why I pointed out the fact I set the project interpreter to 3.5.2.
Done this numerous times, but this package is where I stuck.


I really haven't a slightest clue what's wrong, so please, help me to solve the problem.

2
13 comments

Looks like you have Code Compatibility Inspection enabled. Please check the attached screenshot:

 

 

 

8
Avatar
Permanently deleted user

I tried this option and it still does not resolve the problem

1
Avatar
Permanently deleted user

I have the same error, everywhere I have an f-string I get a "Python version 2.7 does not support a F prefix." None of my projects have Python 2.7 as their interpreter. I followed the instructions above and it didn't change anything, the problem is still there. 

2
Avatar
Permanently deleted user

I ran into this issue, too. It ended up being because of a brew update. I had python3.6 installed and made a symlink for /usr/local/bin/python to the 3.6 version. After brew updated to python3.7, this symlink was broken, and /usr/bin/python was used instead(which was the python2.7 executable that came with MacOS). Updating the symlink to use the python3.7 binary installed by brew fixed this issue. Not sure why this happened when the project had a virtualenv set up, but this solved it nonetheless.

0

I am experiencing the same problem. As suggested above I changed the default python in my PATH (a homebrewed /usr/local/bin/python) to a Python3 interpreter, and the error went away.

While that's a workaround, I feel that PyCharm should only show these errors in the first place when they are actually relevant for the project interpreter, not the system interpreter.

0
Avatar
Permanently deleted user

Hello,

I'm pretty new to this so I'm not sure exactly how to resolve it in the way you guys mentioned above. I'm using Windows 8.1 and I've currently got Python 3.5.3 installed. Can someone please tell me how I update the symlinks to resolve this issue in PyCharm? What do I enter and is it to be done in Anaconda prompt?

 

Kindly,

 

Olivia.

0

Using PyCharm Professional 2019.1

Everything works as expected, until I open another unrelated project (not a Python project) in a separate window.

Then suddenly everywhere I have an f-string I get a "Python version 2.7 does not support a F prefix.

Python interpreter in the project is 3.6.7.  Python interpreter on my system (Ubuntu 18.04) is 2.7.15rc1

Just a guess: after opening the 2nd project, the system interpreter version 'leaks' to the original project.

Have to 1) close the 2nd project;  2) Close the 1st project; 3) Open PyCharm   - then the project version is correctly recognized again.

All along, the terminal inside PyCharm has reported the project interpreter correctly as 3.6.7.

 

0

@Ejner Borgbjerg

I couldn't reproduce the issue. I get no issues with f-strings after opening a second non-python project in a separate window. If the issue is still relevant, I would suggest to submit a bug report to our issue tracker (https://youtrack.jetbrains.com/issues/PY), providing detailed steps to reproduce the issue.

0
Avatar
Permanently deleted user

I used conda to create environment with Python=3.6 and then used the conda Python Interpreter in the settings to set it to the virtual environment created using conda.

0
Avatar
Permanently deleted user

I see this problem when I use pipenv pointing to Python 3.7.x. My interpreter is pointing to Python3.

file:///Users/xxxx/.local/share/virtualenvs/myproject-h0mCcdzP/lib/python3.7
file:///Users/xxxx/.local/share/virtualenvs/myproject-h0mCcdzP/lib/python3.7/lib-dynload
file:///usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7
file:///Users/xxxx/.local/share/virtualenvs/myproject-h0mCcdzP/lib/python3.7/site-packages

But PyCharm still shows "Python version 2.7 does not support a F prefix".

0
Avatar
Permanently deleted user

I solved this but using the menu File --> "Invalidate Caches/Restart".

2

If "Invalidate Caches/Restart" does not work then you can try deleting the ".idea" folder, that worked for me, however that means you are deleting all the project settings.

0

Hi, like our friend Anna said above. This is not a problem.

Everyone that has this 'problem', try this code: 

import statistics
test_scores = [60, 83, 83, 91, 100]
print(statistics.median(test_scores))

It will print '83'.

You guys just have check the code compatibility for python 2.7.

This means that for every misspelling of python 2.7 you will get the error NOTIFICATION, even if you are using another version.

But it is just a NOTIFICATION it will NOT result in errors. 

To remove that annoying NOTIFICATION, do as our friend ANNA saind, in the beginning of this question.

 

0

Please sign in to leave a comment.