简体   繁体   English

使用pyenv-virtualenv触发不同的应用环境

[英]triggering different app environments with pyenv-virtualenv

with virtualenvwrapper, I could setup separate virtualenvs and calling workon venv have them link to specific settings files (ex. test_settings.py or dev_settings.py) I preset using hooks in the virtualenv's bin - preactivate, postactivate, predeactivate and postdeactivate. 使用virtualenvwrapper,我可以设置单独的virtualenvs并调用workon venv将它们链接到特定的设置文件(例如test_settings.py或dev_settings.py)我使用virtualenv的bin中的钩子进行预设 - preactivate,postactivate,predeactivate和postdeactivate。

Is there something equivalent for pyenv? 是否有类似pyenv的东西? pyenv-virtualenv automatically switches virtualenvs based on .python-version set in the current directory, so there's no need to activate and the .pyenv/versions/venv/bin/ dir doesn't have the compliment of hooks that virtualwrapper has anyway. pyenv-virtualenv基于当前目录中设置的.python-version自动切换virtualenvs,因此无需激活,并且.pyenv / versions / venv / bin / dir也没有虚拟包装器所具有的钩子的赞美。

I can easily create different virtualenvs for my various app environments but how can I link them to different environment-specific app settings? 我可以轻松地为各种应用程序环境创建不同的virtualenv,但是如何将它们链接到不同的特定于环境的应用程序设置?

我最后在其他地方阅读了这个论坛回复后,以autoenv的精神将环境变量export something='something-else'命令添加到激活文件~/.pyenv/versions/my_venv/bin/activate

Two ideas: 两个想法:

  • The obvious one: Try the pyenv-virtualenvwrapper plugin to pyenv? 显而易见的一个:尝试pyenv-virtualenvwrapper插件到pyenv?

  • You can add hooks for a specific pyenv command in $PYENV_ROOT/pyenv.d/<command> . 您可以在$PYENV_ROOT/pyenv.d/<command>为特定的pyenv命令添加挂钩。 You can do this even for for pyenv's “porcelain” commands which aren't normally called directly by the user. 您甚至可以为pyenv的“瓷器”命令执行此操作,这些命令通常不会由用户直接调用。 You could write a hook for activate that changes settings based on the name of the virtualenv you're switching to. 您可以编写一个用于activate的挂钩,根据您要切换到的virtualenv的名称更改设置。 (pyenv-virtualenv implicitly pyenv activate when switching to a virtualenv). (切换到virtualenv时,pyenv-virtualenv隐式pyenv activate )。 Note: I've created pyenv hooks, but not for activate , so this is just an idea… 注意:我已经创建了pyenv钩子,但不是为了activate ,所以这只是一个想法......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pyenv-virtualenv 中的环境变量 - Enviroment variables in pyenv-virtualenv pyenv-virtualenv:pyenv中未安装“ 3.6.4” - pyenv-virtualenv: `3.6.4' is not installed in pyenv 在终端启用 pyenv-virtualenv 提示符 - Enable pyenv-virtualenv prompt at terminal 带有pyenv-virtualenv的VSCode,自动触发? - VSCode with pyenv-virtualenv, trigger automatically? 使用 pyenv-virtualenv 设置 virtualenv 时出现 ASCII 编解码器错误 - ASCII codec error when setting up an virtualenv with pyenv-virtualenv pyenv-virtualenv python 版本在 env 激活时不会改变 - pyenv-virtualenv python version does not change on env activation 在`pyenv/pyenv-virtualenv`中,我可以创建一个引用`system`的virtualenv,即之前没有`pyenv install`吗? - in `pyenv/pyenv-virtualenv` can I create a virtualenv which refers to `system`, i.e. without a `pyenv install` before? 从 pyenv-virtualenv 切换到 pipeenv 时保持相同的共享虚拟环境 - Keeping the same, shared virtualenvs when switching from pyenv-virtualenv to pipenv 在pyenv-virtualenv上激活虚拟环境时,如何导出PYTHONPATH? - How to export PYTHONPATH when I activate a virtual environment on pyenv-virtualenv? pyenv-virtualenv 的问题:激活/停用虚拟环境时 Python 和 PIP 未更改 - Issues with pyenv-virtualenv: Python and PIP not changed when activating / deactivating virtual environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM