0

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
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3'
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 Nov 25 '22 at 14:52

2 Answers2

1

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.

modeset
  • 337
  • 2
  • 9
  • Thanks for the hint, there is no ~/.bash_profile on my pi, so I thought it would source ~/.profile (as explained here: https://serverfault.com/questions/261802/what-are-the-functional-differences-between-profile-bash-profile-and-bashrc). I'll give it a try. – Frode Akselsen Jan 21 '20 at 21:10
  • unfortunately it is not working, ~/.bash_profile is getting loaded but for some reason workon remains unfound. – Frode Akselsen 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: https://stackoverflow.com/questions/21928555/virtualenv-workon-command-not-found/49386113 – modeset Jan 21 '20 at 22:02
  • /usr/local/bin is already in PATH, I've run the script and printed it out – Frode Akselsen Jan 22 '20 at 19:46
0

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

source which virtualenvwrapper.sh

sweetdream
  • 101
  • 1
  • 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 Nov 27 '22 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 Nov 27 '22 at 18:17