1

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.

Error Output:

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
"""

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

Please let me know how to resolve this issue.

Narayan
  • 1,670
  • 1
  • 19
  • 37

2 Answers2

2

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.

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
  • This solution works with Pydev too. I got a `RuntimeError: Can't determine home directory` error when importing matplotlib within Pydev but not when using Anaconda's console. Manually setting `HOME` fixes it. – Leonardo Mar 25 '20 at 15:07
0

in git-bash, cmder sys similar problem when calling python based shell need define missing vars by something like: export HOMEPATH="G:/"

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 08 '21 at 15:00
  • Attempted to do something similiar [export HOMEPATH="/c/Users/jason/Documents/GitHub/DAIN/my_package"] failed to work –  Jun 03 '22 at 06:22