Last active
December 15, 2015 17:59
-
-
Save schlamar/5300809 to your computer and use it in GitHub Desktop.
Run pip within Sublime Text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
def _packages_path(): | |
t = os.path.join(os.path.dirname(__file__), '..') | |
return os.path.abspath(t) | |
SITE_PACKAGES = os.path.join(_packages_path(), 'Lib', 'site-packages') | |
_PACKAGING_MODS = os.path.join(_packages_path(), 'Lib', 'packaging') | |
for path in (SITE_PACKAGES, _PACKAGING_MODS): | |
if path not in sys.path: | |
sys.path.insert(0, path) | |
def _fix_pip_env(): | |
sys.argv = ['pip'] | |
sys.__stdout__ = type('', (object,), {'encoding': 'utf-8'})() | |
sys.stdout.isatty = lambda: False | |
fwrite = sys.stdout.write | |
def safe_write(s): | |
if isinstance(s, bytes): | |
return fwrite(s.decode('utf-8')) | |
return fwrite(s) | |
sys.stdout.write = safe_write | |
sys.stdout.buffer = sys.stdout | |
sys.executable = 'C:\\Python33\\python.exe' | |
def install(name): | |
_fix_pip_env() | |
import pip | |
pip.main(['install', '-t', SITE_PACKAGES, name]) | |
# from User import stpip; stpip.install('requests') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment