python subprocess not the def

发布于 2025-02-04 19:44:35 字数 818 浏览 7 评论 0原文

我正在使用子过程调用Python脚本,但它不起作用,因为它找不到我的PythonPath。我有一个我的pythonpath put,它进入了我的文件夹。 假设我的PythonPath包含以下路径:/home/myproject。 我的体系结构是这个:/myproject/djangoview/view_x.py 从我的view_x.py我使用subprocess启动/myproject/scripts/script.py.py

然后启动服务器django上的脚本,我必须单击一个按钮,它应该启动我的script.py,要清楚它确实可以在本地工作,但是它在preprod中不起作用,这是服务器ubuntu。 我遇到的错误是modulenotfound,因为在我的脚本中,我调用/utils/utils.py

所以我只是不太了解我为什么有错误,我的> pythonpath是设置并正确的,所有调用/utils/utils.py的导入都在工作,除非我在preprod Server中使用subprocess。我不能在本地复制它。 有人对这种行为有解释吗?

这是我的电话:

subprocess.run(["nohup python3 /home/myproject/scripts/script.py &"], shell=True)

thanx。

I'm using subprocess to call a python script but it doesn't work because it doesn't find my PYTHONPATH. I have a my PYTHONPATH put and it goes inside my folder.
let's say my PYTHONPATH contains this path: /home/myproject.
My architecture is this one: /myproject/djangoView/view_x.py
from my view_x.py I use subprocess to launch a script that is on /myproject/scripts/script.py

Then I start my server django, I have to click on a button and it should launch my script.py, to be clear it does work in local, but it doesn't work in preprod which is a server ubuntu.
The error I have is ModuleNotFound because in my script I call /utils/utils.py

So I just don't really understand why I have an error, my PYTHONPATH is set and correct, all the imports calling /utils/utils.py are working except when I'm using subprocess in my preprod server. I can't reproduce it in local.
Is someone have an explanation for this behavior ?

Here is my call:

subprocess.run(["nohup python3 /home/myproject/scripts/script.py &"], shell=True)

Thanx.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文