40

When I switch my PyCharm to use Python 3.4.3 and I am getting the error:

Invalid Python SDK

Also PyCharm does not automatically find the Python 3.4 interpreter for me, even though it is on the desired path /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4. See the screenshot:

prompt with error message

Despite this the interpreter does work. I am able to get correct output as expected, but code completion related to Python 3.4 is not working.

E.g. print("hello world!) still shows an error on the editor, but the console shows the correct output.

11 Answers 11

44

This also happened to me. I renamed a repository and then my virtual environment got stuck in the old path.

I grepped all configuration files and could not find any reference to the old one.

What finally solved the problem was to clear caches with the option File > Invalidate Caches / Restart...:

enter image description here

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

2 Comments

This didn't work for me. Mint 18.2, Python 3.6, Pycharm 2017.2.2.
Another possible reason is due to outdated/invalid path in the python interpreter: jetbrains.com/help/pycharm/… So just clear those ones.
9

I had the same issue. Try to comment/remove the PYTHONPATH variable in your ~/.bash_profile

#export PYTHONPATH=/usr/local/lib/python2.7/site-packages/

If it does not help it also may be useful to look in the idea.log for the errors:

/Users/username/Library/Logs/PyCharm40/idea.log

I had the following errors:

Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
     PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages/"
     You should `unset PYTHONPATH` to fix this.

3 Comments

Thanks for the response. I am not seeing the error you are seeing on my logs. but I think there is something wrong with my pythonpath. When I do echo PYTHONPATH, I get response as user/myuser/desktop/ , May be i have changed it accidently , and pycharm is trying to look for sdk there. I tried to unset pythonpath, but it keep saving the same value. Cannot do source .barshrc giving error as file not found, even though file exist at that location. Giving up on pycharm for now, and using pydev which works well
Don't give up! Keep struggling! If you run OS X then it is probably no .bashrc file in your home directory. You should look in .bash_profile. If both of them don't exist just create one manually - it will work! Also, try to brew install python3. It works for me.
Thanks for heading me to right direction. I somehow updated my profile file, with PYTHONPATH value hardcoded. Got rid of it, and everything works great.@mennanov
3

I go the same error message in Windows version of PyCharm after I re-installed Python (3.5) on a different location. The problem was that most of my existing virtual environments registered in PyCharm were still referencing the old installation of Python.

I resolved it by deleting these existing virtual environments and creating a new one. If deleting existing interpreters (in virtual environment) is not an option, you should be able to modify them instead in File | Settings | Project Interpreter

1 Comment

Same problem for me. Specifically the file \venv\Lib\orig-prefix.txt contained an incorrect path to my python (in my case anaconda2). I updated that path and everything came good.
1

I had the same issue in Windows10. I was so frustrated, beacause everything seems looked OK. I've added PYTHONPATH, I've restarted Pycharm and deleted old virtualenv folders and created new... It did't work.

And at the end I have just opened Pycharm in an administrator mode and it works!

Comments

0

I got the same issue, when I updated Python (3.x) version via Home brew in MacOS. Above answers didn't work for me. But with those, I realize that, it's an issue with linking the directories. I deleted ~/.virtualenvs folder and recreated all virtual envs.

$ ls -a ~/.virtualenvs
local-dev wdias-dev
$ rm -rf ~/.virtualenvs
$ which python3
/usr/local/bin/python3
$ mkvirtualenv local-dev --python=/usr/local/bin/python3
$ mkvirtualenv wdias-dev --python=/usr/local/bin/python3

Open the PyCharm again, and it works fine.

1 Comment

I was able to solve this problem by manually setting the python symbolic links in the virtualenv and manually editing pyvenv.cfg in the folder above bin.
0

I couldn't get anything to work, so I cloned my conda env (see how), called it something else, and then set it in PyCharm to the new one.

Comments

0

For me, changing the paths in ~\venv\pyvenv.cfg made PyCharm recognize the new environment after bringing my projects to a new PC.

Comments

0

When creating a new project my interpreter was set to python 2.7 so I had to change that to python3 and everything works like a charm

Comments

0

I got the same problem with Pop OS 21.04 and Pycharm installed via Flatpack. So i remove it and installed via Snap and started working again.

Comments

0

I ended up having to install Python as an admin and make sure it installed to the C:\Program Files\Python310 folder. I think The option was to make sure it installed for all users. If I installed it under for user's appdata it wouldn't work.

Once I did that I was able to point pycharm to the C:\Program Files\Python310\ for the interpreter. Pretty annoying but finally got it working

Comments

0

I've solved it too. Uninstalled python 3.10, installed python 3.9. Changed the python interpreter to 3.9 through pycharm setting. Created a new virtual environment.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.