Running this on Mac OS X El Capitan 10.11.1 in PyCharm 5 (this worked fine in PyCharm 4.5)
import os print("PATH:", os.environ.get("PATH"))
If I run this program with the PyCharm Interpreter project installed in System Python: /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 , here is the result that I get:
PATH: /Users/agautam/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If I run the same program with the project interpreter installed in the /Users/agautam/work/my-awesome-py-project/venv/bin/python3 , I get:
PATH: /usr/bin:/bin:/usr/sbin:/sbin:/Users/agautam/work/my-awesome-py-project/venv/bin
Problem: is that /usr/local/bin disappears when using the virtual environment.
This is how virtual env is created:
import sys, platform, subprocess from os.path import dirname, join root_path = join(dirname(__file__), '../..') venv_path = join(root_path, 'venv') def build_virtual_environment(): print("Building virtual env from Python version", sys.version) # Create a fresh virtual env import venv builder = venv.EnvBuilder(with_pip=True) builder.create(venv_path) # Install dependencies in new virtual env run_in_venv('python', ['-m', 'pip', 'install', '--upgrade', 'pip']) # Upgrade pip itself run_in_venv('pip', ['install', '-r', join(root_path, 'requirements.txt')]) def run_in_venv(cmd, args): if platform.system() == 'Windows': cmd += '.exe' virtual_env_bin_path = r'venv/Scripts' else: virtual_env_bin_path = r'venv/bin' subprocess.check_call([join(root_path, virtual_env_bin_path, cmd)] + args) if __name__ == '__main__': build_virtual_environment()
Additional info: Running python interpreters from the command line gives accurate results (so this seems to be a problem with pycharm):
$ /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ.get("PATH") '/Users/agautam/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' >>> $ ./venv/bin/python3 Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ.get("PATH") '/Users/agautam/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' >>>
Any help / information / pointers would be greatly appreciated.