[英]Running Python using Laravel inside WSL2 Ubuntu causes “modules not found”
I have a WSL2 Ubuntu set up with everything needed to run python scripts.我有一个 WSL2 Ubuntu 设置了运行 python 脚本所需的一切。
I am also using a Laravel App that uses Symfony/Process to run said-python scripts.我还使用了一个 Laravel 应用程序,它使用 Symfony/Process 来运行所说的 python 脚本。
But when I run the script using the Laravel App, it tells me a module needed for that script is not installed.但是当我使用 Laravel 应用程序运行脚本时,它告诉我没有安装该脚本所需的模块。
I verified that it is installed in my Ubuntu system, and even ran the script using CLI.我验证它安装在我的 Ubuntu 系统中,甚至使用 CLI 运行脚本。
This is what I use for my process in my Laravel Controller这就是我在 Laravel Controller 中用于我的流程的内容
$process = new Process(['/bin/python3', base_path() . /resources/python/pythonscript.py']
and this is what I use for the CLI command这就是我用于 CLI 命令的内容
/bin/python3 /var/www/laravel/resources/python/pythonscript.py
(I can also use just python3, but I wanted to make sure that using /bin/python3 works.) (我也可以只使用 python3,但我想确保使用 /bin/python3 有效。)
To reiterate, the CLI works perfectly fine, while the Laravel Controller gives me a重申一下,CLI 运行良好,而 Laravel Controller 给了我一个
ModuleNotFoundError: No module named 'sklearn' ModuleNotFoundError:没有名为“sklearn”的模块
Any Advice?有什么建议吗?
The issue was that the group www-data did not have access to where I installed the modules.问题是组 www-data 无权访问我安装模块的位置。 Which was in my default $user.在我的默认 $user 中。
To fix this, I had to install the modules using sudo.为了解决这个问题,我必须使用 sudo 安装模块。
e.x sudo pip3 install yfinance
Not so sure if this is a good solution, but it's a solution that works for me.不太确定这是否是一个好的解决方案,但它是一个适合我的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.