简体   繁体   中英

What should my path if I am using python venv?

I use python 3.6.9 and asterisk 16.16.0 in Ubuntu 18.04. If you know about AGI then you probably know about this line #!/usr/bin/python or this #!/usr/bin/env python if not then don't worry its tells the system to run this script in the Python interpreter.

So as far you know what I can do. but now my question is if I am use virtual environment for python using help of venv package and want defines path of that python environment in my AGI then what should I define.

My virtual environment store in following directory: /home/test/Documents/environments/test_env .

When you are running ANY agi script in asterisk it will run under asterisk user.

Asterisk user on most systems is limited user and may have no python environment at all.

Best way is create virtual environment for your python and use full path for your python INSIDE venv like /opt/my_virtual_env/bin/python3 in all agi scripts.

Ensure that those path is readable by asterisk user or owned by asterisk user

Try adding this path to the $PATH variable

/home/test/Documents/environments/test_env/bin

This directory contains scripts like activate , deactivate etc. which are used for activating and deactivating the virtual env.

Regarding the shebang, #!/usr/bin/env python should work properly if the virtual env is activated .

Hope this is what you were looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM