简体   繁体   English

从包含 venv 文件夹的文件夹中激活 virtualenv

[英]activate a virtualenv from inside a folder containing venv folder

I have the following folder structure:我有以下文件夹结构:

Folder
  |- working_folder  # other stuff in here.
  |- venv  # my venv folder

Depending on platform (windows or linux) I would enter the venv and activate the appropriate script to activate the virtualenv.根据平台(windows 或 linux),我会输入 venv 并激活相应的脚本来激活 virtualenv。 But especially when you're inside the "working_folder" there is a lot of typing involved to get to the venv,script and activation of the venv.但特别是当您在“working_folder”中时,需要大量输入才能进入 venv、脚本和激活 venv。

Lazy as I am I wonder whether there is a more convenient way.我很懒,我想知道是否有更方便的方法。 I am thinking of some kind of python script looking for a venv folder and automatically activate that virtual environment.我正在考虑某种 python 脚本寻找 venv 文件夹并自动激活该虚拟环境。

The looking for a venv folder is the easy part.寻找一个 venv 文件夹是很容易的部分。 But I am getting stuck on how to use a python script to activate my current shell with that virtual env.但是我在如何使用 python 脚本来激活我当前的shell 与该虚拟环境陷入困境。

Anyone any suggestions?有人有什么建议吗? BTW.顺便提一句。 I am looking for both a linux and windows solution.我正在寻找 linux 和 windows 解决方案。

I think you are looking for this - https://virtualenvwrapper.readthedocs.io/en/latest/ (this is not a python script, but it will be more convenient)我想你正在寻找这个 - https://virtualenvwrapper.readthedocs.io/en/latest/ (这不是 python 脚本,但它会更方便)

For example, to activate virtual env with virtualenvwrapper all you need is to type this command:例如,要使用 virtualenvwrapper 激活虚拟环境,您只需键入以下命令:

workon name_of_your_venv

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM