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.

11 comments
Comment actions Permalink

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

 

 

 

2
Comment actions Permalink

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

1
Comment actions Permalink

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. 

1
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

@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
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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

1

Please sign in to leave a comment.