das Lauf auf Mac OS X El Capitan 10.11.1 in PyCharm 5Warum ist PyCharm auf einem Mac/usr/local/bin zu entfernen, während eine Python virtuelle Umgebung mit
import os
print("PATH:", os.environ.get("PATH"))
(Dies wurde in PyCharm 4,5 feinen Arbeiten)
Wenn ich dieses Programm mit PyCharm Projekt Interpreter Satz im System der Python ausführen: /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
, hier ist die Ausgabe erhalte ich:
PATH: /Users/agautam/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Wenn ich das gleiche Programm mit Projekt Interpreter auf einer virtuellen Umgebung laufen /Users/agautam/work/my-awesome-py-project/venv/bin/python3
ich :
PATH: /usr/bin:/bin:/usr/sbin:/sbin:/Users/agautam/work/my-awesome-py-project/venv/bin
Das Problem: ist, dass /usr/local/bin
verloren geht, wenn ich eine virtuelle Umgebung.
Hier ist, wie die virtuelle env erstellt:
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()
Zusätzliche Informationen: Ausführen des Python-Interpreter von der Kommandozeile erzeugt exakt die gleichen Ergebnisse (so scheint es, ist es eine PyCharm Ausgabe):
$ /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'
>>>
Jede Hilfe/Informationen/Hinweise werden sehr geschätzt.
Haben Sie das jemals herausgefunden? –
Nein. Workaround - fügen Sie/usr/local/bin zur Run config hinzu. –
@AjayGautam, können Sie spezifisch sein, was Sie mit add X zur Run config meinen? Das könnte sogar eine Antwort sein ... –