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?
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.Frode Akselsen– Frode Akselsen2020年01月21日 21:10:04 +00:00Commented Jan 21, 2020 at 21:10 -
unfortunately it is not working, ~/.bash_profile is getting loaded but for some reason
workon
remains unfound.Frode Akselsen– Frode Akselsen2020年01月21日 21:34:22 +00:00Commented 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– modeset2020年01月21日 21:58:22 +00:00Commented Jan 21, 2020 at 21:58 -
This could be helpful too: stackoverflow.com/questions/21928555/…modeset– modeset2020年01月21日 22:02:47 +00:00Commented Jan 21, 2020 at 22:02
-
/usr/local/bin is already in PATH, I've run the script and printed it outFrode Akselsen– Frode Akselsen2020年01月22日 19:46:11 +00:00Commented 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.2022年11月27日 18:15:07 +00:00Commented 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 correctlyjsotola– jsotola2022年11月27日 18:17:50 +00:00Commented Nov 27, 2022 at 18:17
.profile
into.bash_profile
(that one runs whenever a shell is started).