Virtualenv installation commandline sensor

Yesterday I’ve reinstalled Hass for the future with python 3.6. I’m using dietpi on a pine A64.
I’ve installed python 3.6 with following script:

#!/bin/sh
RELEASE=3.6.3

# install dependencies
sudo apt-get install libbz2-dev liblzma-dev libsqlite3-dev libncurses5-dev libgdbm-dev zlib1g-dev libreadline-dev libssl-
dev tk-dev

# download and build Python
mkdir ~/python3
cd ~/python3
wget https://www.python.org/ftp/python/$RELEASE/Python-$RELEASE.tar.xz
tar xvf Python-$RELEASE.tar.xz
cd Python-$RELEASE
./configure
make
sudo make install
sudo rm -rf ~/python3/Python-$RELEASE
cd ~

Then i’ve installed hass following the docs with virtualenv https://home-assistant.io/docs/installation/virtualenv/
Now i’ve added a commandline sensor with following command:

python -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

and it didn’t run everytime I’ve got an error
Now I found out what the problem was the command was run in the normal python environment and not in the virtualenv(in the normal env requests was not installed).
normally the command should be run in the virtualenv so somethings wrong but can’t find out what.

if I check the status of systemctl I get the following:

/srv/homeassistant/bin/python3.6 /srv/homeassistant/bin/hass

I think you could activate the virtualenv before running the command

Try

source /srv/homeassistant/bin/activate; python -c "import requests; print(requests.get('https://pypi.python.org/pypi/homeassistant/json').json()['info']['version'])"

yeah maybe but you would expect that if you execute something from hass it would run in the virtualenv no?

I believe the command_line starts a new shell, which wouldn’t inherit the virtual environment.

In general, you wouldn’t want to use the HA virtual environment as it is normally specific to HA. Since you know it has the components you need, it makes sense for you to use it in this case, but in general another python program would use its own virtual environment.

indeed just checked the sourcecode

return_value = subprocess.check_output(
            command, shell=shell, timeout=15)

I just thought it would be in the same environment but what you say makes sense.
thanks