39

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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
rayonst
  • 403
  • 1
  • 5
  • 7

11 Answers11

39

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

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • 3
    This didn't work for me. Mint 18.2, Python 3.6, Pycharm 2017.2.2. – CoderGuy123 Aug 31 '17 at 15:36
  • Another possible reason is due to outdated/invalid path in the python interpreter: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#interpreter So just clear those ones. – Weel Oct 20 '21 at 18:43
7

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.
mennanov
  • 1,195
  • 3
  • 16
  • 27
  • 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 – rayonst Sep 03 '15 at 17:19
  • 1
    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. – mennanov Sep 03 '15 at 23:25
  • 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 – rayonst Sep 04 '15 at 13:46
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

ldiary
  • 494
  • 2
  • 8
  • 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. – MeterLongCat Apr 07 '17 at 01:59
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.

gihanchanuka
  • 4,783
  • 2
  • 32
  • 32
  • 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. – Chuck Jan 28 '21 at 19:19
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.

osuwireless
  • 627
  • 7
  • 6
0

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

alex_555
  • 1,092
  • 1
  • 14
  • 27
0

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!

Helena
  • 1
  • 1
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

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.

mcrrnz
  • 545
  • 6
  • 10
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

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.