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.

5
  • Could you include a photo of what the interpreter is listed as at the bottom right of the screen? Commented Mar 25, 2021 at 1:12
  • @GeorgeAdams Added image Commented Mar 25, 2021 at 1: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 and clear the environment variables to make sure there's nothing to fall back on. The Windows integrated python is best left alone. Commented Mar 25, 2021 at 1:30
  • Your 3.7 path is suspicious, there's no good reason to install a Python interpreter to users\AppData\local\... Commented Mar 25, 2021 at 1: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. Commented Mar 25, 2021 at 1:42

1 Answer 1

4

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.