Pycharm Terminal fails to activate virtual env

Completed

When I click Terminal, it does not activate the virtualenv environment.

How to recreate:

  • I create a new project, selecting the option to create a new environment using Virtualenv.
  • Once the project is created, I check the settings and the Project Interpreter is set to use it, the Python Console uses it, if I add packages, they are installed in the venv directory as expected, and the Tools/Terminal settings page has the 'Activate virtualenv' option selected
  • I click the Terminal button at the bottom of the screen, and the terminal is started but the virtualenv environment is not activated.

I would be grateful for some help.

Thank you.

32 comments
Comment actions Permalink

Update: The problem seems to have been solved - it would have been much easier to solve were it not for PyCharm having hidden the error message thrown up by the activate.bat file.

When activating the environment by running the activate.bat file manually, it worked but also threw up an error message. I wonder whether PyCharm saw the error message and abandoned the activation, bringing up the normal terminal instead. Had PyCharm shown me the error message rather than hiding it I would have had a clue to the source of the problem.

In my case, the error was caused by the fact that my path string for some reason contained some rogue quotation marks. Once they were removed, and after closing and opening PyCharm again, it started working.

0
Comment actions Permalink

Exactly the same continues happening. 

I had the same problem I was installing the packages on my terminal in pycharm and then I noticed that the "site packages" on the venv had nothing but the basics (setuptools and pip). 
Then I open a windows terminal and noticed that all of the packages were isntalled from 2 of my virtual environments that I created in the base environment. 

I had to manually run activate,bat on pycharm terminal.

On my settings >>Tools >> Terminal the option to activate enviroment was also selected. 

So there is a bug in here most probably.  

I expect that the the activate.bat is auto recognized.  

2
Comment actions Permalink

I'm struggling with exactly the same thing. Could you solve it? I already have a full venv working fine until yesterday. After closing pycharm and reopening today, the terminal won't open the venv anymore. 

 

How can I at least open it manually?

 

Than you,

1
Comment actions Permalink

Dear LSM Liborio, 

In my case the terminal opened. The problem for me was that the venv never got activated. So every time I did pip install it installed the modules on the base environment from python. 

To correct this I had to open the terminal and then run manually the activate.bat file from the location of the created environment. \\venv\\Scripts\\activate.bat

1
Comment actions Permalink

Thank you Lainez,

Yeah. this is exactly what is happening to me, my terminal opens just fine, but out of venv. 

I could manage to activate the venv manually, but I'd like to understand what happened, why is it not automatic, like used to be.

0
Comment actions Permalink

Hello Rafael, 

 

Do you have "Activate virtualenv" option enabled in Settings/Preferences | Tools | Terminal? Please attach a screenshot. 

0
Comment actions Permalink

oh! I've just found the problem source.

 

Mrs. Belianskaya, I checked the "Activate virtualenv" option in my settings and it was enabled.

After that, I found in settings -> projects -> project structure

the venv folder was marked as "excluded" and there is an option to include it back. Solved!

1
Comment actions Permalink

I had the same problem.

Venv was not shown inside IntelliJ IDEA terminal even if it was set up, I solved going to File. -> Project Structure -> Modules -> add module  after that IntelliJ showed me a popup to configure Python

0
Comment actions Permalink

Antonina Belianskaya 

the screenshot that you request attach. Everything ok on this point. It was like this and this I checked also before posting. 

 

Lsm Liborio 

This was the problem source, cool that you found the solution Thanks a lot.

 

But nevertheless, isn't it a bug from the IDE Antonina Belianskaya? Since it gives out a false positive that the environment is active on the terminal when it is not? Or is it a desired behavior? 
I have to do this manually on every project that I have created, either the Lsm Liborio solution or the manual activation on the terminal of the environment as a temporary solution that I saw.  

0
Comment actions Permalink

Rafael Lainez

I can't reproduce the issue so far. The 'venv' directory should be excluded, this should not affect virtualenv activation. Could be related to interpreter paths. Have you tried to delete/recreate project interpreter?

0
Comment actions Permalink

Hello,

I have the same problem. I tried all steps written here. even update and reinstall PyCharm doen't help.

I don't know what caused this but it is present in all my projects and even in new projects with a new venv.

1
Comment actions Permalink

Hey people,

Check if you had some sort of silent command blocking PyCharm to activate the virtual env.

I've got the same "issue" - in the past, PyCharm was nicely activating the virtual environment when opened a terminal session within.
That stopped working - until I realized an otherwise nice and useful bash script is blocking PyCharm to activate the venv.

The bash script is actually a wrapper of the "script" command - a Linux terminal session recorder - which silently collects the STDOUT to a file. The wrapper function is removing all ANSI codes from the logs and spits out a  pure .txt file for me.

So when I start up a new terminal session in PyCharm I've got the message from the script wrapper but no venv.
If I exit the wrapper (enter exit to a recorded session) got the venv activated.


  

0
Comment actions Permalink

I had it working. This has nothing to do with pycharm.

My issue was about anaconda HKEY_CURRENT_USER was still there even after unistall it.

1-You must check your PATH environment variable  echo %PATH% in command prompt and check for paths that do not exist anymore or check for "&" sign and remove them.

2-The following worked for me:

  1. Open the Registry Editor (press windows key, type regedit and hit Enter) .
  2. Navigate to HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun and clear the values.
  3. Also check HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun.

Thanks to  aishanib7 on https://stackoverflow.com/a/60122860 !

 

0
Comment actions Permalink

so far, nothing worked for me. I have still the same issue.

1
Comment actions Permalink

Hello Richard Fiebelkorn , 

 

Please provide more details, screenshots: project structure, interpreter settings, terminal settings, and terminal view. 

 

Thank you!

0
Comment actions Permalink

Hello guys, I had this problem for a quite long time, the one thing that solved for me was the python.exe interpreter file PATH. I don't have any idea why did this happen, everything was working fine before, the only problem was this(venv won't auto execute in pycharm terminal), but after then, completly solved:

In the windows environment variables setup, PATH, was like this:

C:\Users\lsmli\AppData\Local\Programs\Python\Python36\

I just added ANOTHER line with the interpreter:

C:\Users\lsmli\AppData\Local\Programs\Python\Python36\python.exe

 

0
Comment actions Permalink

Hi Antonina Belianskaya,

I took some screenshots as you asked for. I hope they show all the informations you need - if not, please let me know and I will take some more.

I created a new project with a new VENV based on Python 3.7.
I am using PyCharm Community 2020.1.4

 

Thank You.

0
Comment actions Permalink

Hello Richard Fiebelkorn , 

Please try the solution provided in this comment: 

  https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003647920/comments/360002071920

 

python.exe was not added for some reason to the PATH  (the list of interpreter paths on the first screenshot provided by you)

0
Comment actions Permalink

Hi Antonina Belianskaya,

I dried the solution already and to be sure I tried it again. But it does not solve the problem.

What I also did, was installing Python 3.8 and creating a new venv based on this Version and with this venv based on python 3.8 it works again.

I will try to reinstall python 3.7 to double check.

0
Comment actions Permalink

Hi Antonina Belianskaya,

I dried the solution already and to be sure I tried it again. But it does not solve the problem.

What I also did, was installing Python 3.8 and creating a new venv based on this Version and with this venv based on python 3.8 it works again.

I will try to reinstall python 3.7 to double check.

I uninstalled my python 3.7.3 and installed python 3.7.8 and created new venv and now its working again.

Thx

0
Comment actions Permalink

I solved this by:

File - >  Settings -> Project [Python Interpreter]

In the drop down at the top, select the one from your env.  Mine was set to the global interpreter - so I changed it.  Once that was set to the correct one, without restarting, any new terminals I opened were locked into the env.

1
Comment actions Permalink

Hi Guys,

i had the same problem that venv wasnt shown in the terminal.

My solution was to uninstall python and install it again with the difference that i put a checkmarc on the path. 

I hope this works for you too.

 

Have a nice day

 

Best Regards,

Juan

0
Comment actions Permalink

Hi Antonina Belianskaya,

If I use PowerShell to pycharm's terminal,but the virtual environment cannot be automatic,can you help me.

 

0
Comment actions Permalink

Hello Kerwin,

there is a bug  https://youtrack.jetbrains.com/issue/PY-22469 , could you please call

echo $env:VIRTUAL_ENV ? 

Does it show the venv location? 

 

0
Comment actions Permalink

was facing the same issue, changed the shell path from powershell to cmd in the terminal setting and now the terminals have the virtualenv activated, maybe an issue with powershell ?

3
Comment actions Permalink

Ashishbekal97 Same symptoms here, doesn't automatically activate with Powershell but does with cmd. It does correctly activate the environment however when using the command 'activate venv' once the powershell terminal has been launched.

Antonina Belianskaya is it possible the issue is caused by the topic listed here? python - virtualenv in PowerShell? - Stack Overflow. I'd rather use powershell than be forced to use cmd.

0
Comment actions Permalink

Ashishbekal97 Thank you very much, you comment helps me to solve my problem!

 

0
Comment actions Permalink

For Powershell activation issues, please follow/vote for: https://youtrack.jetbrains.com/issue/PY-52766

0

Please sign in to leave a comment.