推荐学习书目
› 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
pirates
V2EX  ›  Python

如何指定脚本中的 Python 模块执行时的 virtualenv?

  •  
  •   pirates ·
    oucb · May 11, 2017 · 4396 views
    This topic created in 3468 days ago, the information mentioned may be changed or developed.
    假设有一个 example.sh 文件,里面有一行‘ flask run ’,并且指定了 FLASK_APP。该文件用于启动运行 flask 项目,但终端执行’ sh example.sh'时,即使激活了 virtualenv,项目的运行环境还是系统默认的 python 环境,请问如何指定为特定的 virtualenv ?
    10 replies  •  2017-05-12 13:07:00 +08:00
    kier
    kier
    May 11, 2017
    1
    一般不是 env/bin/python app.py 么?
    Cooky
    Cooky
    May 11, 2017 via Android
    2
    在脚本里加 active 啊,还能怎么办 - -|||
    est
    est
    May 11, 2017
    3
    不用激活 venv。直接指定 venv 所在 python 路径即可。

    比如 source /my_path/venv/bin/activate; python xxx.py 改为:

    /my_path/venv/bin/python xxx.py 即可。自动 venv 了。
    syahd
    syahd
    May 11, 2017 via Android
    4
    难道不是写解释器的绝对路径就可以了吗
    pirates
    pirates
    OP
    May 11, 2017
    5
    @Cooky 在脚本中 source 激活 virtualenv 就行,一直在终端激活,谢谢!
    pirates
    pirates
    OP
    May 11, 2017
    6
    @kier
    @est 这样也行。由于整个项目都要在指定环境下运行,所以就直接在脚本中增加一行‘ source venv/bin/activate ’
    mxi1
    mxi1
    May 11, 2017 via iPhone
    7
    运行的时候把配置相关的事情都丢给 uwgi 之类的服务嘛
    julyclyde
    julyclyde
    May 11, 2017
    8
    不需要 activate
    直接用 virtualenv “里面”的 python 来执行就可以了
    ( scl/pyenv 除外)
    zhengxiaowai
    zhengxiaowai
    May 11, 2017
    9
    $YOUR_PAROJECT_PATH/venv/bin/python app.py
    RealLiuSha
    RealLiuSha
    May 12, 2017
    10
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1434 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:11 · PVG 19:11 · LAX 03:11 · JFK 06:11
    ♥ Do have faith in what you're doing.