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

Hi, 

 

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
/home/anna/Programming/Shopping_Tracker/venv/bin/python

And these are from PyCharm's Terminal:

(venv) python --version
Python 3.7.3

(venv) which python
/home/anna/Programming/Shopping_Tracker/venv/bin/python

So the versions should be the same to my understanding.

Has anyone encountered a similar issue?

4 comments
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


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),
})
0
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',
'/home/anna/.local/bin',
'/usr/local/sbin',
'/usr/local/bin',
'/usr/sbin',
'/usr/bin',
'/sbin',
'/bin',
'/usr/games',
'/usr/local/games'],
'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': ['',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/anna/Programming/Shopping_Tracker/venv/lib/python3.6/site-packages'],
'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'

0
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',
'/app/bin',
'/usr/bin'],
'sys.path': ['/app/pycharm/helpers/pydev',
'/app/pycharm/helpers/third_party/thriftpy',
'/app/pycharm/helpers/pydev',
'/usr/lib/python37.zip',
'/usr/lib/python3.7',
'/usr/lib/python3.7/lib-dynload',
'/home/anna/Programming/Shopping_Tracker'],
'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.

0
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. 

1

Please sign in to leave a comment.