简体   繁体   English

如果我使用 python venv,我的路径应该是什么?

[英]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.此目录包含用于激活和停用虚拟环境的脚本,如activatedeactivate等。

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.

相关问题 我不小心删除了 vs code 上的 python venv 文件夹,我该怎么办? - I accidentally deleted my python venv folder on vs code, what should i do? 当我尝试在 python 中设置我自己的 VENV 时访问被拒绝,我该怎么办? - Access Denied when I tried setting my own VENV in python, what do I do? 我正在使用 python 的 glob 模块并得到一个空列表作为回报。 我应该怎么办? - I am using glob module of python and getting an empty list in return. what should i do? 在MacOS上安装用户的python包路径应该是什么? - What should be my python packages path for a user install on MacOS? 我应该在Python类中重构什么? - What should I refactor in my Python Class? 在venv和PyCharm中使用Python - Using Python with venv and PyCharm geckodriver 路径错误 - 如果我使用批处理文件启动我的 python 脚本 - geckodriver path error - if i am using a batch file to start my python script 使用和不使用Python运行venv命令之间有什么区别? - What is difference between using and not using Python to run the venv command? 我无法解码逻辑以打印以下 python 模式。 我应该对我的代码进行哪些更改? - I am unable to decode the logic to print the following python pattern. What changes should I do in my code? 我应该把我的 python 文件放在 venv 文件夹中的什么位置? - Where do I put my python files in the venv folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM