在我的Laravel(php)产品中,我们称为python脚本。当我在命令提示符下运行此脚本时,它运行正常。但是从Laravel控制器提出了一个错误。
错误输出:
Traceback (most recent call last):
File "../public/calcuter_py/TestBasic_Mtg_Calculator.py", line 11, in <module>
import MortgageUtilFuncs
File "D:\Apache24\htdocs\projectname\public\calcuter_py\MortgageUtilFuncs.py", line 9, in <module>
import pandas as pd
File "C:\Python\lib\site-packages\pandas\__init__.py", line 55, in <module>
from pandas.core.api import (
File "C:\Python\lib\site-packages\pandas\core\api.py", line 24, in <module>
from pandas.core.groupby import Grouper, NamedAgg
File "C:\Python\lib\site-packages\pandas\core\groupby\__init__.py", line 1, in <module>
from pandas.core.groupby.generic import ( # noqa: F401
File "C:\Python\lib\site-packages\pandas\core\groupby\generic.py", line 44, in <module>
from pandas.core.frame import DataFrame
File "C:\Python\lib\site-packages\pandas\core\frame.py", line 115, in <module>
from pandas.core.series import Series
File "C:\Python\lib\site-packages\pandas\core\series.py", line 84, in <module>
import pandas.plotting
File "C:\Python\lib\site-packages\pandas\plotting\__init__.py", line 59, in <module>
from pandas.plotting._core import (
File "C:\Python\lib\site-packages\pandas\plotting\_core.py", line 17, in <module>
import pandas.plotting._matplotlib # noqa
File "C:\Python\lib\site-packages\pandas\plotting\_matplotlib\__init__.py", line 3, in <module>
from pandas.plotting._matplotlib.boxplot import (
File "C:\Python\lib\site-packages\pandas\plotting\_matplotlib\boxplot.py", line 14, in <module>
from pandas.plotting._matplotlib.core import LinePlot, MPLPlot
File "C:\Python\lib\site-packages\pandas\plotting\_matplotlib\core.py", line 34, in <module>
from pandas.plotting._matplotlib.tools import (
File "C:\Python\lib\site-packages\pandas\plotting\_matplotlib\tools.py", line 5, in <module>
import matplotlib.table
File "C:\Python\lib\site-packages\matplotlib\table.py", line 25, in <module>
from .text import Text
File "C:\Python\lib\site-packages\matplotlib\text.py", line 14, in <module>
from .font_manager import FontProperties
File "C:\Python\lib\site-packages\matplotlib\font_manager.py", line 103, in <module>
os.path.join(str(Path.home()), r'AppData\Local\Microsoft\Windows\Fonts'),
File "C:\Python\lib\pathlib.py", line 1071, in home
return cls(cls()._flavour.gethomedir(None))
File "C:\Python\lib\pathlib.py", line 264, in gethomedir
raise RuntimeError("Can't determine home directory")
RuntimeError: Can't determine home directory
"""
我们正在使用laravel流程功能来执行此python脚本。
请让我知道如何解决此问题。
答案 0 :(得分:0)
我遇到了与您相同的问题,我可以通过手动设置变量来解决问题,因为问题是
os.environ['HOME']
为空,这导致了问题
因此您可以使用此代码手动设置
os.environ['HOME'] = 'C:/Python'
设置时请检查您使用的是“ /”而不是“ \”,否则会出现错误。
它解决了我的问题。我也使用Apache并调用Python脚本,并确保您的代码在脚本顶部具有python路径
#!C:\Python\python.exe