Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Python script that activates the virtualenv and then runs another Python script?

On Windows Vista, I need a script that starts the activate (to activate the virtualenv) script in:

C:\Users\Admin\Desktop\venv\Scripts\ 

And later, in the virtual environment, starts to the manage.py runserver in the folder:

C:\Users\Admin\Desktop\helloworld\ 

How should I do? What modules should I use?

like image 810
ugavetheroses Avatar asked Jun 18 '15 23:06

ugavetheroses


People also ask

How do I run a Python script from the virtual environment from the command line?

To use the virtual environment you created to run Python scripts, simply invoke Python from the command line in the context where you activated it. For instance, to run a script, just run python myscript.py .

What does activate bat do?

Schedule the activate. bat itself and it will automatically run your script after the virtual environment activated.


2 Answers

You can activate your virtualenv and then start server using a bat file. Copy this script in to a file and save it with .bat extension (eg. runserver.bat)

@echo off cmd /k "cd /d C:\Users\Admin\Desktop\venv\Scripts & activate & cd /d    C:\Users\Admin\Desktop\helloworld & python manage.py runserver" 

Then you can just run this bat file (just double click) to start the server

like image 89
Ashish Gupta Avatar answered Oct 05 '22 19:10

Ashish Gupta


runserver.bat:

 CALL [your path]\Scripts\activate.bat  python manage.py runserver 
like image 21
Weihui Guo Avatar answered Oct 05 '22 18:10

Weihui Guo