Two names were proposed for a path, and I— I chose the one with a space, And that has made all the difference. -- in tribute to Robert Frost
On Ubuntu, I put my django + celery + virtualenv project in a path with a space, just being consistent with the Windows counterpart. It tured out to be a total adventure for me.
First, all the scripts in the virtual environment cannot be run.
zsh: ./pip: bad interpreter: "/opt/broken_path_preceding_a_space: no such file or directory"
So I fixed shebang line by:
sudo sed -i '1 s|^.*$|#!/usr/bin/env python|' "$INSTDIR/venv/bin/celery"
$INSTDIR is the path with space where virtual environment
venv is installed, and the
sed command just replaces the first line with
#!/usr/bin/env python. This works because
activate script prepends
However, it does not work if running the scripts with sudo:
> $INSTDIR/venv/bin/activate (venv) > which python > $INSTDIR/venv/bin/python > sudo which python > /usr/bin/python
venv only modifies the current user’s
> env | grep ^PATH PATH=$INSTDIR/venv/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin > sudo env | grep ^PATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin
See also this.
Although it is fine to call the script with
$INSTDIR/venv/bin/python -m pip, running celeryd requires sudo:
which cannot find python packages installed in the virtual environment.
sudo env "PATH=$PATH" /etc/init.d/celeryd
Or keep calm and remove the space…