I am trying to pass a variable from PHP to Python on Windows, but the line "import pandas" is causing an issue. All my code below is bare-bones of the actual process I am trying to create for simplicity. The first chunk of code is my Index, the second is the PHP code called by Index.php, and the last chunk is Python.
Index.php
<!DOCTYPE html>
<html>
<head>
<b>Enter a folder path </b>
</head>
<body>
<form action="BlastParse.php" method="post">
Path: <input type ="text" name="path"><br>
<input type="submit">
</form>
</body>
</html>
BlastParse.php
<html>
<body>
<?php
#getting path passed from index.php
$masterpath = $_POST["path"];
echo 'The path requested to be passed is: ' . $masterpath . '<br>';
#my directories
$python = 'C:/Users/Garrett/Anaconda3/python.exe';
$pyscript = 'C:/Users/Garrett/Documents/Python/temp.py';
$pyscriptPrimed = $pyscript . ' ';
#creating the command
$command ="$python $pyscriptPrimed";
#executing the command to call temp.py; adding passed path to command
exec($command .$masterpath, $output, $return_var);
?>
</body>
</html>
temp.py
import os
import sys
#path passed into python from php
file_path = sys.argv[1]
#file_path = 'Write this string to file'
with open("C:/Users/Garrett/Documents/Python/copy.txt", 'w') as file:
file.write(file_path)
#PROBLEM HERE
import pandas as pd
with open("C:/Users/Garrett/Documents/Python/copy2.txt", 'w') as file:
file.write(file_path)
I am using the writing to copy.txt and copy2.txt for debugging purposes roughly since there isn't anything produced on the terminal. When I comment out the import pandas line, the copy2.txt file is created and written to properly. If not, the copy2.txt file is not created and the $return_var variable returns a 1 in PHP (which I'm not sure what the error code represents yet).
I am running on Windows 10 with Python 3.7, and using VS Code through Anaconda.