Laravel to Python RuntimeError:无法确定主目录 [英] Laravel to Python RuntimeError: Can't determine home directory

查看:79
本文介绍了Laravel to Python RuntimeError:无法确定主目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Laravel(php)产品中,我们称为python脚本.当我在命令提示符下运行此脚本时,它运行正常.但是从Laravel控制器提出了一个错误.

In my Laravel (php) product we are calling the python script. While I run this script in command prompt it's working fine. But from Laravel controller it raised an error.

错误输出:

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脚本.

We are using laravel process features to execute this python script.

请让我知道如何解决此问题.

Please let me know how to resolve this issue.

推荐答案

我遇到了与您相同的问题,我可以通过手动设置变量来解决问题,因为问题是

I was having the same problem as you do, I could solved it out by setting up the variable manually as the problem was that

os.environ['HOME']

为空,这是导致问题的原因

was being none, which was causing the problem

因此您可以使用此代码手动设置

So you can set it up manually with this code

os.environ['HOME'] = 'C:/Python'

设置时请检查您使用的是"/"而不是"\",否则会出现错误.

Check that you are using "/" and not "\" when setting up, otherwise it will give you an error.

它解决了我的问题.我也使用Apache并调用Python脚本,并确保您的代码在脚本顶部具有python路径

It solved my problem. I'm using Apache as well and calling a Python script and also make sure that your code has the path of python on the top of your script

#!C:\Python\python.exe

这篇关于Laravel to Python RuntimeError:无法确定主目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆