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?

asked Jan 21, 2020 at 20:29
1
  • Move the stuff you've added to .profile into .bash_profile (that one runs whenever a shell is started). Commented Nov 25, 2022 at 14:52

2 Answers 2

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.

answered Jan 21, 2020 at 20:54
5
  • 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. Commented Jan 21, 2020 at 21:58
  • This could be helpful too: stackoverflow.com/questions/21928555/… 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
0

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

source which virtualenvwrapper.sh

answered Nov 24, 2022 at 14:07
2
  • 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. 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 Commented Nov 27, 2022 at 18:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.