-->

bat文件可以启动虚拟环境然后继续在虚拟环境里进行操作吗?

2019-01-02 21:52发布

问题:

我写了一个bat文件,内容如下,它可以创建一个名为test的虚拟环境。

@echo off

python -m venv test
.\test\Scripts\activate

pip install sample.whl
deactivate
pause

用activate启动虚拟环境后,进入虚拟环境,bat文件里的pip install sample.whl以后的命令行就不执行了。
请问有什么方法可以让bat文件在虚拟环境中执行pip install sample.whl以后的命令行吗?

回答1:

可以先运行 pip install sample.whl ,然后启动虚拟机,参考 https://virtualenv.readthedocs.io/en/latest/userguide/ :

If you build with virtualenv --system-site-packages ENV, your virtual environment will inherit packages from /usr/lib/python2.7/site-packages (or wherever your global site-packages directory is).



标签: