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?


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. Jan 21 '20 at 21:10
  • unfortunately it is not working, ~/.bash_profile is getting loaded but for some reason workon remains unfound. Jan 21 '20 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
    Jan 21 '20 at 21:58
  • This could be helpful too: stackoverflow.com/questions/21928555/…
    – modeset
    Jan 21 '20 at 22:02
  • /usr/local/bin is already in PATH, I've run the script and printed it out Jan 22 '20 at 19:46

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.