V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
smartdie
V2EX  ›  Python

如何在终端下 cd 到项目目录里时自动载入 virtualenv 呢

  •  
  •   smartdie · 2015-11-13 14:03:29 +08:00 · 2426 次点击
    这是一个创建于 3093 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这几天用 openstack ,发现 openstack 里能够自动检测当前目录是否使用 python virtualenv ,源码看不太明白,请教一下是否有人了解原理呢。
    4 条回复    2015-11-13 14:59:50 +08:00
    julyclyde
        1
    julyclyde  
       2015-11-13 14:28:19 +08:00
    照那个“显示当前目录的 git branch 名字”的脚本抄抄
    hujianxin
        2
    hujianxin  
       2015-11-13 14:42:41 +08:00
    pyenv 可以实现
    smartdie
        3
    smartdie  
    OP
       2015-11-13 14:57:45 +08:00
    @julyclyde
    @hujianxin
    感谢二位答复,我刚才 google 了一下( https://gist.github.com/noroutine/55c49ee39e65a5643302
    http://kabike.iteye.com/blog/1970864

    大致明白了,是利用 bash 的 PROMPT_COMMAND 命令,对当前操作的目录做检查然后自动执行虚拟环境脚本。
    aliuwr
        4
    aliuwr  
       2015-11-13 14:59:50 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2055 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:05 · PVG 00:05 · LAX 09:05 · JFK 12:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.