I am running a bash script that activates a virtualenvironment workon myenv on the raspberry pi and then runs a python script.

Unfortunately, the virtual environment cannot be activated, I get the error workon: command not found

I came across the answer here: https://stackoverflow.com/questions/34611394/virtualenv-workon-command-not-found/34611480

and added following lines to my ~/.profile (and also to ~/.bashrc) file:

export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

Then I've rebooted my raspberry pi but it only works if I add a line source ~/.profile in my bash script. So, it seems like the .profile is not loaded when a bash script is executed.

I am logging into my rpi via ssh.

Any clue what else I could try out?

  • Move the stuff you've added to .profile into .bash_profile (that one runs whenever a shell is started).
    – Dougie
    Commented Nov 25, 2022 at 14:52

2 Answers 2


Have a look at this question which explains the difference between .bashrc and .bash_profile.

X11 will look at your .bashrc while a "regular" Terminal will look at .bash_profile

So you will need to use .bash_profile in your case.

  • Thanks for the hint, there is no ~/.bash_profile on my pi, so I thought it would source ~/.profile (as explained here: serverfault.com/questions/261802/…). I'll give it a try. Commented Jan 21, 2020 at 21:10
  • unfortunately it is not working, ~/.bash_profile is getting loaded but for some reason workon remains unfound. Commented Jan 21, 2020 at 21:34
  • @FrodeAkselsen Can you try adding /usr/local/bin to your PATH variable? e.g. in ~/.bash_profile, add this line at the beginning: export PATH="/usr/local/bin:$PATH" You will need to either load ~/.bash_profile or restart your shell before changes are loaded, by the way. It doesn't exist by default either, but don't worry - if it is created it will get used.
    – modeset
    Commented Jan 21, 2020 at 21:58
  • This could be helpful too: stackoverflow.com/questions/21928555/…
    – modeset
    Commented Jan 21, 2020 at 22:02
  • /usr/local/bin is already in PATH, I've run the script and printed it out Commented Jan 22, 2020 at 19:46

The trick I found is to add the following line on top of the script

source which virtualenvwrapper.sh

  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Nov 27, 2022 at 18:15
  • you said add the following line, but you presented two lines ... please format your snippet as code so that it shows up correctly
    – jsotola
    Commented Nov 27, 2022 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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