简体   繁体   中英

How Can I Active Virtual Environment Using .bat File?

I have finished working on Django project, but I don't want to Deploy it to the server right now I want to use this system on my local host. I tried to create a file with bat extension, and this one is to open the project on the Chrome browser This file will work when opened The question is how with this file can I run the project virtual environment

The code that works is 'manager.bat':

start cmd /k start chrome http://127.0.0.1:8000/admin/
cd manager/venv/Manager 
python manage.py runserver

But when adding this statement:

activate

Then, when executing the file again, it exits the cmd without executing anything

Code not working:

start cmd /k start chrome http://127.0.0.1:8000/admin/
cd manager/venv
cd Scripts
activate
cd ..
cd Manager
python manage.py runserver
  • 'activate' instruction is to activate the virtual environment, when I type it on cmd it works successfully,, look: [enter image description here][1] The idea is that I don't want every time to open the cmd, run the virtual environment, and run the server manually

[This is on cmd and it works][1] [1]: https://i.stack.imgur.com/k5XIe.png

Open Notepad and Write the following code, also change directory name as your need and save it as ***.bat file in your desktop

@echo off
cmd /k "cd /d E:\ProjectsFolder\projectenv\Scripts & activate & cd /d    E:\ProjectsFolder\projectenv\myproject & python manage.py runserver"

Maybe this link help you to Activate environment, run the project then open the browser.

try to follow it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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