1

I am facing a strange issue in PyCharm. I have defined a virtual environment "(venv)" having Python3.8 as base as interpreter for project along with rest of packages required for the project. The same is selected in project run/debug configuration as well. See pictures below.

Virtual Environment set for project

Virtual Environment set for Run/Debug configs

My virtual environment has Python-3.8, however, when I try to run project, it tries to run the project with Python-3.7 present elsewhere in the PC. Here is that pic : PyCharm call after pressing Run button

Furthermore, the interpreter listed in PyCharm at bottom right of the screen is correct as shown in figure: enter image description here

I have seen a similar question answered here: PyCharm not using my configured virtualenv interpreter however the remedy suggested there doesn't work for me.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Abhinav
  • 1,882
  • 1
  • 18
  • 34
  • Could you include a photo of what the interpreter is listed as at the bottom right of the screen? – George Adams Mar 25 '21 at 01:12
  • @GeorgeAdams Added image – Abhinav Mar 25 '21 at 01:15
  • You're doing it right and there's no explanation for this. Except if for some reason the Python3.8 interpreter doesn't get resolved and the system falls back on the Python3.7 installation because it's on your PATH environment variable. Try using [where python](https://ss64.com/nt/where.html) and clear the [environment variables](https://superuser.com/questions/949560) to make sure there's nothing to fall back on. [The Windows integrated python](https://docs.python.org/3/using/windows.html#the-microsoft-store-package) is best left alone. – bad_coder Mar 25 '21 at 01:30
  • Your 3.7 path is suspicious, there's no good reason to install a Python interpreter to `users\AppData\local\...` – bad_coder Mar 25 '21 at 01:33
  • Yes, not sure why it calls that. However, my "AppData/Local/Programs/Python" has directories for all three versions on my machine, i.e. 3.7, 3.8 and 3.9. Furthermore, calling python in cmd prompt calls python-3.8 as that is what is present first in my Windows Environment Variables. – Abhinav Mar 25 '21 at 01:42

1 Answers1

2

After help from a lot of colleagues at work, I finally found the bugger. In the Run/Debug configuration, there is a checkbox saying "include parent environment variables" checkbox which was checked in my case. And that was the problem. For this reason, the virtual environment interpreter was being over-ridden. This checkbox can be found as shown in images below :

enter image description here

enter image description here

Abhinav
  • 1,882
  • 1
  • 18
  • 34