Shift 'n Tab
Shift 'n Tab

Reputation: 9443

How to run django server with ACTIVATED virtualenv using batch file (.bat)

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.

Upvotes: 3

Views: 8036

Answers (5)

Erd
Erd

Reputation: 1

I had to use absolute path to python in order to run "manage.py".

cmd /k "cd /d C:\path\to\project\.venv\Scripts & activate & python C:\path\to\project\manage.py runserver"

where & activate runs C:\path\to\project\.venv\Scripts\activate.bat and & python runs python at C:\path\to\project\.venv\Scripts\python

you get the same result with:

call "C:\path\to\project\.venv\Scripts\activate.bat"
C:\path\to\project\.venv\Scripts\python "C:\path\to\project\manage.py" runserver

I guess my problem is that i have many pythons installed

Upvotes: 0

Shift 'n Tab
Shift 'n Tab

Reputation: 9443

Found my solution by encoding this:

@echo off
cmd /k "cd /d C:\path\to\your\env\scripts & activate & cd /d C:\path\to\your\env\[projectname] & python manage.py runserver"

Upvotes: 10

If your virtualenv is created via virtualenvwrapper:

workon yourenvname & python manage.py runserver

Upvotes: 0

Bart Römgens
Bart Römgens

Reputation: 131

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

Upvotes: 5

devxplorer
devxplorer

Reputation: 637

try \path\to\env\Scripts\activate

and look at virtualenv docs

Upvotes: 1

Related Questions