3

I found this post to be useful on how to code a batch file to automate django web server start.

But the problem is, there is no virtualenv activated, How can i activate it before the manage.py runserver inside the script?

I would like to run this server with virtualenv activated via batch file.

Community
  • 1
  • 1
Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117

4 Answers4

9

Found my solution by encoding this:

@echo off
cmd /k "cd /d C:\Users\[user]\path\to\your\env\scripts & activate & cd /d C:\Users\[user]\path\to\your\env\[projectname] & python manage.py runserver"
Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117
  • This solution work for me, If your folder name have space doesn't matter. example : `cmd /k "cd /d C:\Users\[user]\path\to\my folder name with space\env\scripts & activate & cd /d C:\Users\[user]\path\to\your\env\[projectname] & python manage.py runserver" ` – Tomy Aug 26 '22 at 08:41
5

Call the activate.bat script in your batch file, before you run manage.py,

CALL \path\to\env\Scripts\activate.bat
python manage.py runserver
Bart Römgens
  • 121
  • 1
  • 3
1

try \path\to\env\Scripts\activate

and look at virtualenv docs

devxplorer
  • 678
  • 1
  • 4
  • 10
  • Thanks for your response but this script is good for ubuntu and i am looking for windows – Shift 'n Tab Sep 29 '16 at 06:22
  • From docs: "On Windows, the equivalent activate script is in the Scripts folder:> \path\to\env\Scripts\activate" – devxplorer Sep 29 '16 at 06:33
  • also you can try to install https://pypi.python.org/pypi/virtualenvwrapper-win on windows and activate your virtualenv with `workon` keyword – devxplorer Sep 29 '16 at 06:38
  • i tried and tried but it doesnt work. but i just solve my problem here http://stackoverflow.com/questions/30927567/a-python-script-that-activates-the-virtualenv-and-then-runs-another-python-scrip – Shift 'n Tab Sep 29 '16 at 07:01
  • yeah, looks like it *.bat features, sorry that misled – devxplorer Sep 29 '16 at 07:12
0

If your virtualenv is created via virtualenvwrapper:

workon yourenvname & python manage.py runserver