简体   繁体   中英

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.

I am also using a Laravel App that uses Symfony/Process to run said-python scripts.

But when I run the script using the Laravel App, it tells me a module needed for that script is not installed.

I verified that it is installed in my Ubuntu system, and even ran the script using CLI.

This is what I use for my process in my Laravel Controller

$process = new Process(['/bin/python3', base_path() . /resources/python/pythonscript.py']

and this is what I use for the CLI command

/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.)

To reiterate, the CLI works perfectly fine, while the Laravel Controller gives me a

ModuleNotFoundError: No module named 'sklearn'

Any Advice?

The issue was that the group www-data did not have access to where I installed the modules. Which was in my default $user.

To fix this, I had to install the modules using 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM