[英]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.我在 Ubuntu 18.04 中使用 python 3.6.9 和星号 16.16.0。 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.如果您了解 AGI,那么您可能知道这一行#!/usr/bin/python
或这一行#!/usr/bin/env python
如果不知道,请不要担心它会告诉系统在 Python 解释器中运行此脚本.
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.但现在我的问题是,如果我在 venv package 的帮助下使用python的虚拟环境,并希望在我的 AGI 中定义 python 环境的路径,那么我应该定义什么。
My virtual environment store in following directory: /home/test/Documents/environments/test_env .我的虚拟环境存储在以下目录中: /home/test/Documents/environments/test_env 。
When you are running ANY agi script in asterisk it will run under asterisk user.当您在星号中运行任何 agi 脚本时,它将在星号用户下运行。
Asterisk user on most systems is limited user and may have no python environment at all.大多数系统上的 Asterisk 用户是受限用户,可能根本没有 python 环境。
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.最好的方法是为您的 python 创建虚拟环境,并在所有 agi 脚本中使用 python INSIDE venv 的完整路径,例如 /opt/my_virtual_env/bin/python3。
Ensure that those path is readable by asterisk user or owned by asterisk user确保这些路径可由星号用户读取或由星号用户拥有
Try adding this path to the $PATH
variable尝试将此路径添加到$PATH
变量
/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.此目录包含用于激活和停用虚拟环境的脚本,如activate
、 deactivate
等。
Regarding the shebang, #!/usr/bin/env python
should work properly if the virtual env is activated .关于shebang,如果激活了虚拟环境, #!/usr/bin/env python
应该可以正常工作。
Hope this is what you were looking for.希望这就是你要找的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.