推荐学习书目
› 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 · Nov 13, 2015 · 3349 views
    This topic created in 3973 days ago, the information mentioned may be changed or developed.
    这几天用 openstack ,发现 openstack 里能够自动检测当前目录是否使用 python virtualenv ,源码看不太明白,请教一下是否有人了解原理呢。
    4 replies  •  2015-11-13 14:59:50 +08:00
    julyclyde
        1
    julyclyde  
       Nov 13, 2015
    照那个“显示当前目录的 git branch 名字”的脚本抄抄
    hujianxin
        2
    hujianxin  
       Nov 13, 2015
    pyenv 可以实现
    smartdie
        3
    smartdie  
    OP
       Nov 13, 2015
    @julyclyde
    @hujianxin
    感谢二位答复,我刚才 google 了一下( https://gist.github.com/noroutine/55c49ee39e65a5643302 ,
    http://kabike.iteye.com/blog/1970864 )

    大致明白了,是利用 bash 的 PROMPT_COMMAND 命令,对当前操作的目录做检查然后自动执行虚拟环境脚本。
    aliuwr
        4
    aliuwr  
       Nov 13, 2015
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   934 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:21 · PVG 03:21 · LAX 12:21 · JFK 15:21
    ♥ Do have faith in what you're doing.