Terminal instance not using project's venv

Some basics: I am running Pycharm 2020.3.3 and WIndows 10. I installed Python 3.9 which I use as my standard interpreter.

I am having trouble with Pycharm's terminal and its use of venv. The terminal's venv is not using the project's venv, they list or show me different installed modules and / or versions. The modules listed in Project view are in-sync with those listed in the project's interpreter. In Terminal settings "Shell integration" and "Activate venv" are ticked on. Do I misunderstand is? I would expect Pycharm's terminal instance to use the Project's instance. I found several topics regarding this or a similar issue but I am not sure if they really cover the same issue.

7 comments
Comment actions Permalink

Hello, 

 

Please attach screenshots: 

1.  Project Interpreter Settings https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

2. Terminal settings https://www.jetbrains.com/help/pycharm/settings-tools-terminal.html

3.  output in PyCharm's terminal of the command "where python"

4. "pip freeze" output

0
Comment actions Permalink

Hey,

thanks for the answer. I already opened a bug (PY-46769) and added the screenshots in question. I think it is better to follow up there.

0
Comment actions Permalink

I'm seeing the same issue on PyCharm 2021.2 (PE) on a Mac.

0
Comment actions Permalink

Swinters Hi, does it help to remove and re-add the interpreter in PyCharm? If not, could you please provide the output of the interpreter diagnostic script from both PyCharm and the terminal (for comparison)? 

0
Comment actions Permalink

Andrey Resler I am having the same issue. I have removed and re-added the interpreter multiple times and nothing changes. I'm using bash as my terminal. Please help as I'd like to be able to open a new terminal and it auto-activate my venv.

0
Comment actions Permalink

JetBrains support helped me identify my issue...basically, it was an operator error. (highly embarrassing given my prior years as a senior UNIX admin ;-))

Summary: if you're working with python on a *nix host, run "alias" at your command line...if you see "python" in that output, then the rest of this comment should help you address your problem

My problem was due to the fact that I had "python" aliased to the system release of python in /usr/local/bin. (Prior to installing PyCharm, I had just been editing 2.7 python files using vi. As I was transitioning to python3 though, I got tired of always typing "python3" so I created an alias in my .bashrc that pointed "python" to "/usr/local/bin/python3" so that I would bypass any python2 links or PATH references.)

The reason this was a difficult issue to troubleshoot is that a "which python" always correctly returned the reference to the virtual environment python; however, because I aliased "python", the incorrect python version was actually being brought in. ("which" traverses the PATH environment and doesn't know or care about command aliases).

Bottom line for python....don't use aliases ;-)

0
Comment actions Permalink

Swinters

Thanks for the response! Sadly that is not my issue. Here's my output for 'alias':

0

Please sign in to leave a comment.