Daily Archives: November 30, 2016

Virtualenv in PyCharm

Run below code, we can check what package we have under current environment.

import subprocess

p = subprocess.Popen(['pip', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

env1

In PyCharm -> Project Interpreter -> list box Project Interpreter, here are all the python environments:
setting

Under system button, select Create VirtualEnv
create_new_virtualenv

create_new_virtualenv2

Now, we have new virtual environment.
create_new_virtualenv3

Let’s try the code again. We see the package list changed.
env2

Not ended yet….

Let’s open terminal console in PyCharm and try virtualenv activate command. Unfortunately, it shows that it couldn’t find source command, which is different from Linux.
source_fail

To activate virtualenv in Windows, we end up with running Scripts\activate.bat command in env folder.
source_fail2