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
Roel
  • 7,836
  • 10
  • 69
  • 108

4 Answers4

8

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"
Roel
  • 7,836
  • 10
  • 69
  • 108
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
  • 638
  • 1
  • 4
  • 10
  • Thanks for your response but this script is good for ubuntu and i am looking for windows – Roel 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 – Roel 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