Different Python version in Terminal and PyCharm despite using the very same venv and path



I'm setting up PyCharm for my app development and have encountered a strange issue. Even though I set my project to use the very same virtual environment (I used the built-in venv) and made sure PyCharm's interpreter points to the same path, the versions of Python are different.

Everything I googled up was someone's not setting the interpreter inside PyCharm correctly. I also checked PyCharm's guide and haven't found anything that I haven't already tried.

These are the results from the Terminal (I'm using Linux Mint 19), inside my venv:

(venv) x:~/Programming/Shopping_Tracker$ python --version
Python 3.6.7

(venv) x:~/Programming/Shopping_Tracker$ which python

And these are from PyCharm's Terminal:

(venv) python --version
Python 3.7.3

(venv) which python

So the versions should be the same to my understanding.

Has anyone encountered a similar issue?

Comment actions Permalink

Very strange. Never seen such issue before.

Please run the following script from both terminals and post the output:

import sys
import os
import pkg_resources
from pprint import pprint

'sys.version_info': sys.version_info,
'sys.prefix': sys.prefix,
'sys.path': sys.path,
'pkg_resources.working_set': list(pkg_resources.working_set),
'PATH': os.environ['PATH'].split(os.pathsep),
Comment actions Permalink

Hey, so here'e the output from the OS Terminal, outside PyCharm, inside the venv:

{'PATH': ['/home/anna/Programming/Shopping_Tracker/venv/bin',
'pkg_resources.working_set': [six 1.12.0 (/home/anna/Programming/Shopping_Tracker/venv/lib/python3.6/site-packages),
setuptools 39.0.1 (/home/anna/Programming/Shopping_Tracker/venv/lib/python3.6/site-packages),
python-dateutil 2.8.0 (/home/anna/Programming/Shopping_Tracker/venv/lib/python3.6/site-packages),
pkg-resources 0.0.0 (/home/anna/Programming/Shopping_Tracker/venv/lib/python3.6/site-packages),
pip 9.0.1 (/home/anna/Programming/Shopping_Tracker/venv/lib/python3.6/site-packages)],
'sys.path': ['',
'sys.prefix': '/home/anna/Programming/Shopping_Tracker/venv',
'sys.version_info': sys.version_info(major=3, minor=6, micro=7, releaselevel='final', serial=0)}


And unfortunately, the output from the PyCharm Terminal shows this error (same venv is active in PyCharm):

Traceback (most recent call last):
File "<input>", line 3, in <module>
File "/app/pycharm/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'pkg_resources'

Comment actions Permalink

@Andrey Resler

When I run your script in PyCharm excluding pkg resources, I get this output:

{'PATH': ['/home/anna/Programming/Shopping_Tracker/venv/bin',
'sys.path': ['/app/pycharm/helpers/pydev',
'sys.prefix': '/home/anna/Programming/Shopping_Tracker/venv',
'sys.version_info': sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)}


I hope it still helps.

Comment actions Permalink

Something is definitely wrong with your environment or interpreter.

Please try to delete venv directory, then create a new interpreter with a new virtualenv environment in PyCharm. 

Comment actions Permalink

I also experienced this issue in Pycharm Community version 2019.2.4. But this issue not exist in version 2019.1.4.

Comment actions Permalink

I am getting a very similar issue. I have 4 folders added to a project, and each has its own "venv" because I can also use them separately. The terminal is using the second folder's "venv" instead of the first folder. I want it to use the first folder's "venv" so it's frustrating that it won't do that.


Please sign in to leave a comment.