Pycharm detected global interpreter instead venv

Hi! I'm trying to assoсiate my existing project with venv. I selected my venv in Python Interpreter in my project settings. Terminal shows: '(venv) C:\Users\...' - looks like ok. But result 'where python' is: 'C:\Users\myUser\AppData\Local\Programs\Python\Python37\python.exe' - global interpreter. So 'pip list' shows global packages instead venv packages. How can I fix it? 

8 comments
Comment actions Permalink

Could you please attach a screenshot of interpreter paths https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-reloading-interpreter-paths.html#view? 

And the output of the script :

 

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),
'os.environ': {
name: value.split(os.pathsep) if 'PATH' in name else value
for name, value in os.environ.items()
},
})


0
Comment actions Permalink
(env) C:\Users\dfgar\Documents\School\courses\python-web\python-projects\djangotestshome\djangotests>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 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),
... 'os.environ': {
... name: value.split(os.pathsep) if 'PATH' in name else value
... for name, value in os.environ.items()
... },
... })
{'os.environ': {'ALLUSERSPROFILE': 'C:\\ProgramData',
'APPDATA': 'C:\\Users\\dfgar\\AppData\\Roaming',
'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files',
'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common '
'Files',
'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files',
'COMPUTERNAME': 'I9',
'COMSPEC': 'C:\\Windows\\system32\\cmd.exe',
'DRIVERDATA': 'C:\\Windows\\System32\\Drivers\\DriverData',
'FPS_BROWSER_APP_PROFILE_STRING': 'Internet Explorer',
'FPS_BROWSER_USER_PROFILE_STRING': 'Default',
'HOMEDRIVE': 'C:',
'HOMEPATH': ['\\Users\\dfgar'],
'IDEA_INITIAL_DIRECTORY': 'C:\\Program '
'Files\\JetBrains\\PyCharm '
'2020.3.3\\jbr\\bin',
'INTELLIJ IDEA': 'C:\\Program Files\\JetBrains\\IntelliJ IDEA '
'2020.3.2\\bin;',
'LOCALAPPDATA': 'C:\\Users\\dfgar\\AppData\\Local',
'LOGONSERVER': '\\\\I9',
'NUMBER_OF_PROCESSORS': '20',
'ONEDRIVE': 'C:\\Users\\dfgar\\OneDrive',
'ONEDRIVECONSUMER': 'C:\\Users\\dfgar\\OneDrive',
'OS': 'Windows_NT',
'PATH': ['C:\\Users\\dfgar\\Documents\\School\\courses\\python-web\\python-projects-prod\\djangotests-home\\env\\Scripts',
'C:\\Windows\\system32',
'C:\\Windows',
'C:\\Windows\\System32\\Wbem',
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Windows\\System32\\OpenSSH\\',
'C:\\Program Files\\PuTTY\\',
'C:\\Program Files\\dotnet\\',
'C:\\Program Files\\nodejs\\',
'C:\\Program Files\\Git\\cmd',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python39\\',
'C:\\Users\\dfgar\\AppData\\Local\\Microsoft\\WindowsApps',
'',
'C:\\Program Files\\JetBrains\\PyCharm 2020.3.3\\bin',
'',
'C:\\Program Files\\JetBrains\\PyCharm Community '
'Edition 2020.3.3\\bin',
'',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Microsoft '
'VS Code\\bin',
'C:\\Users\\dfgar\\.dotnet\\tools',
'C:\\Users\\dfgar\\AppData\\Roaming\\npm',
'C:\\Program Files\\JetBrains\\IntelliJ IDEA '
'2020.3.2\\bin',
'',
'C:\\Program Files\\heroku\\bin'],
'PATHEXT': ['.COM',
'.EXE',
'.BAT',
'.CMD',
'.VBS',
'.VBE',
'.JS',
'.JSE',
'.WSF',
'.WSH',
'.MSC'],
'PROCESSOR_ARCHITECTURE': 'AMD64',
'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 165 Stepping '
'5, GenuineIntel',
'PROCESSOR_LEVEL': '6',
'PROCESSOR_REVISION': 'a505',
'PROGRAMDATA': 'C:\\ProgramData',
'PROGRAMFILES': 'C:\\Program Files',
'PROGRAMFILES(X86)': 'C:\\Program Files (x86)',
'PROGRAMW6432': 'C:\\Program Files',
'PROMPT': '(env) $P$G',
'PSMODULEPATH': ['C:\\Program '
'Files\\WindowsPowerShell\\Modules',
'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules'],
'PUBLIC': 'C:\\Users\\Public',
'PYCHARM': 'C:\\Program Files\\JetBrains\\PyCharm '
'2020.3.3\\bin;',
'PYCHARM COMMUNITY EDITION': 'C:\\Program '
'Files\\JetBrains\\PyCharm '
'Community Edition 2020.3.3\\bin;',
'SESSIONNAME': 'Console',
'SYSTEMDRIVE': 'C:',
'SYSTEMROOT': 'C:\\Windows',
'TEMP': 'C:\\Users\\dfgar\\AppData\\Local\\Temp',
'TERMINAL_EMULATOR': 'JetBrains-JediTerm',
'TERM_SESSION_ID': 'a803fe82-2d45-4a30-bd7c-553ca041d871',
'TMP': 'C:\\Users\\dfgar\\AppData\\Local\\Temp',
'USERDOMAIN': 'I9',
'USERDOMAIN_ROAMINGPROFILE': 'I9',
'USERNAME': 'dfgar',
'USERPROFILE': 'C:\\Users\\dfgar',
'VIRTUAL_ENV': 'C:\\Users\\dfgar\\Documents\\School\\courses\\python-web\\python-projects-prod\\djangotests-home\\env',
'WINDIR': 'C:\\Windows',
'_OLD_VIRTUAL_PATH': ['C:\\Windows\\system32',
'C:\\Windows',
'C:\\Windows\\System32\\Wbem',
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\',
'C:\\Windows\\System32\\OpenSSH\\',
'C:\\Program Files\\PuTTY\\',
'C:\\Program Files\\dotnet\\',
'C:\\Program Files\\nodejs\\',
'C:\\Program Files\\Git\\cmd',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\Scripts\\',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python39\\',
'C:\\Users\\dfgar\\AppData\\Local\\Microsoft\\WindowsApps',
'',
'C:\\Program Files\\JetBrains\\PyCharm '
'2020.3.3\\bin',
'',
'C:\\Program Files\\JetBrains\\PyCharm '
'Community Edition 2020.3.3\\bin',
'',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Microsoft '
'VS Code\\bin',
'C:\\Users\\dfgar\\.dotnet\\tools',
'C:\\Users\\dfgar\\AppData\\Roaming\\npm',
'C:\\Program Files\\JetBrains\\IntelliJ '
'IDEA 2020.3.2\\bin',
'',
'C:\\Program Files\\heroku\\bin'],
'_OLD_VIRTUAL_PROMPT': '$P$G',
'__INTELLIJ_COMMAND_HISTFILE__': 'C:\\Users\\dfgar\\AppData\\Local\\JetBrains\\PyCharm2021.1\\terminal\\history\\djangotests-history8'},
'pkg_resources.working_set': [zipp 3.4.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
XlsxWriter 1.3.7 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
xlrd 2.0.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Werkzeug 1.0.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
virtualenvwrapper 4.8.4 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
virtualenvwrapper-win 1.2.6 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
virtualenv 20.4.2 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
virtualenv-clone 0.5.4 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
typing-extensions 3.7.4.3 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
stevedore 3.3.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
sqlparse 0.4.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
SQLAlchemy 1.4.10 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
six 1.15.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
setuptools 40.8.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
pytz 2021.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
python-editor 1.0.4 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
python-dateutil 2.8.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
pip 21.0.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
pbr 5.5.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
pandas 1.2.2 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
openpyxl 3.0.6 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
numpy 1.20.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
MarkupSafe 1.1.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Mako 1.1.4 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Jinja2 2.11.3 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
jdcal 1.4.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
itsdangerous 1.1.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
importlib-metadata 3.6.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
greenlet 1.0.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Flask 1.1.2 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Flask-SQLAlchemy 2.5.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Flask-Migrate 2.7.0 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
filelock 3.0.12 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
et-xmlfile 1.0.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
Django 3.1.7 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
django-environ 0.4.5 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
distlib 0.3.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
click 7.1.2 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
asgiref 3.3.1 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
appdirs 1.4.4 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages),
alembic 1.5.8 (c:\users\dfgar\appdata\local\programs\python\python37\lib\site-packages)],
'sys.path': ['',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\lib',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37',
'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages'],
'sys.prefix': 'C:\\Users\\dfgar\\AppData\\Local\\Programs\\Python\\Python37',
'sys.version_info': sys.version_info(major=3, minor=7, micro=4, releaselevel='final', serial=0)}
>>>

0
Comment actions Permalink

Hello, 

 

Thank you for the output. 

While I am investigating, please activate the same venv in command line and run ``where python``. Will you have the same result? Please attach a screenshot as well. 

0
Comment actions Permalink

Hi! So, this situation isn't PyCharm's problem but i think you can make new helpful feature.

It happens if rename/change venv's parent directory.

The solve:

  1. update path to venv inside all files in venv/scripts (activate, activate.bat, Activate.ps1. If there is Django then django-admin.py). 
  2. in terminal: deactivate venv and activate again
  3. in PyCharm Add interpreter - existing environment
  4. # reinstall pip
    python -m pip install --upgrade --force-reinstall pip

It will be very unpleasant if you forget call peep > freeze then change project's and venv's directory then call pip > freeze again - pip will be executed as global, but not venv. And you requirements.txt will have global packages. 

If PyCharm show me this notification (or solve this problem itself) it will be cool. 

But now, I can't repeat this problem because when I try to move my project and open it in PyCharm and change project interpreter - all working good. 

 

0

Please sign in to leave a comment.