Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Activate a Python Virtual Environment Automatically on Login?

I have a Python virtual environment named venv in the user home directory. I would like to activate this virtual environment on login. I don't want to type source venv/bin/activate each time after login. I want to type python something.py and have it always use the virtual environment.

How can I do this in the user's login scripts?

The user is only ever going to do python development in this particular virtual environment.

like image 940
Utkonos Avatar asked Oct 16 '25 19:10

Utkonos


1 Answers

There might be better ways of doing this but the simplest way I can think of is modifying .bashrc file if you are using an OS Like Ubuntu. In your .bashrc file you can add a line to start your virtual environment. An example could be adding the following to the bottom of your .bashrc file:

source myvenv/bin/activate
like image 114
cangozpi Avatar answered Oct 19 '25 10:10

cangozpi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!