I am new to Ubuntu and Python virtualenv. Since I realized the importance of virtualenv, I'd like to use it by default whenever I run python(from installing packages) so that I don't need to run source bin/activate every time.


if you are using virtualenv to create a virtual environment, it should be activated (manually or automatically) through running:

source PATH_TO_MY_ENV/bin/activate

However, when you don't want to type this every time and want to run it automatically by your desktop start-up, you should follow these three steps:

1. Create a shell script activate_my_env.sh and put the above mentioned command in it:

# activate_my_env.sh

source PATH_TO_MY_ENV/bin/activate

2. Then, you need to change the permissions for activate_my_env.sh script to be executable (chmod +x):

chmod +x /path_to_your_file/activate_my_env.sh

NOTE: In this step you can also activate your environment without typing source my_env/bin/activate, but still need to run your script with this command:


3. Finally, in order to run the shell script automatically, you should set it to be run by start-up / reboot of your system:

  • A. edit contab file:

    crontab -e

  • B. add the following line to this contab file:

    @reboot /path_to_you_file/activate_my_env.sh

Reboot your system and you should have your virtual environment activated automatically, after every ubuntu startup.

More about Running Shell Script by Ubuntu Startup


I think the easiest way is to install Anaconda or Miniconda. It creates a virtual environment named base and makes it the default. So whenever you fire up your terminal, you will have base activated. Everything you install using conda or pip will be installed in the base. Now please note that you may still need to use virtual environments. For example, you may have a Django 2.0 project and a Django 1.0 project. Then you need to keep 2 different virtual environments (say venv1 and venv2) with Django 2.0 in the venv2 and Django 1.0 in venv1. Otherwise you will have dependency errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.