简体   繁体   English

在 WSL2 Ubuntu 中使用 Laravel 运行 Python 会导致“找不到模块”

[英]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.

相关问题 在 WSL2 Ubuntu 中使用 Python 的 Kafka 消费者/生产者 - Kafka consumer/producer with Python in WSL2 Ubuntu 在 WSL2 上的 Ubuntu 中为 jupyter 实验室扩展安装 nodejs - Installing nodejs for jupyter lab extensions inside Ubuntu on WSL2 WSL2 上的 Python Ubuntu 启动。json 参数 - Python on WSL2 Ubuntu launch.json args 运行 Ubuntu 18 LTS 的 WSL2 上出现 Pyperclip 错误,同时尝试访问从 windows 复制的数据 - Pyperclip error on WSL2 running Ubuntu 18 LTS while trying to access data copied from windows Jupyter Notebook 无法在 Ubuntu WSL2 中打开 - Jupyter Notebook cannot open in Ubuntu WSL2 在 Ubuntu(WSL1 和 WSL2)中显示 matplotlib 图(和其他 GUI) - Show matplotlib plots (and other GUI) in Ubuntu (WSL1 & WSL2) 在 Windows 中从 ubuntu wsl 运行 pyspark,错误:找不到 cmd - pyspark running from ubuntu wsl in windows, error: cmd not found 在“外部”驱动器上的 WSL2 中创建 python venv - Creating a python venv in WSL2 on "external" drive 在 vscode 中找不到 python 调试适配器 - WSL:Ubuntu - python debug adapter not being found in vscode - WSL:Ubuntu 让 Kivy 在 Win10 上的 WSL2 上的 Ubuntu 中工作 - Getting Kivy to work in Ubuntu on WSL2 on Win10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM