Issue with Modules when calling python through a shell

I am calling a python script through a VBA script. This works as intended until I tried calling a script that imports a handful of libraries. Some libraries seem to have trouble loading when I call python this way but not others. (Jupyter Lab and calling the .py file from the command prompt both work seamlessly.) The error message I get is “DLL load failed while importing qhull: The specified module could not be found.”

Some modules seem to be loading while others cause issues. SciPy and sklearn are the ones causing me problems. How should I go about troubleshooting this error? Could it have something to do with the use of shell?

Here is the VBA code I am using to execute the .py script

Sub xls2py()
Dim objShell As Object
Dim PythonExe, PythonScript As String
ChDir ActiveWorkbook.Path

    Set objShell = VBA.CreateObject("Wscript.Shell")

    PythonExe = """C:UsersPeter_KAnaconda3python.exe"""
    PythonScript = "C:UsersPeter_KDesktopUntitled1.py"

    objShell.Run PythonExe & PythonScript
    Set objShell = Nothing

End Sub

Also, Here is the section of the python code that is responsible for importing libraries

import csv
import os
import math
import numpy as np
import pandas as pd
from scipy.optimize import minimize
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score
from openpyxl import load_workbook
from datetime import datetime
import time as tm

Answer

Did you install the dependency using pip3? If you are using Python3 and install a dependency using pip it may fail to import it properly. Try to reinstall the dependencies using pip3 and see if it solves the issue