title: Calling Python(Anaconda) Script(importing library issue) from Java
body: <p>I am trying to call python script from java code.</p>
  
  <pre><code>public class PythonTest {
      public static void main(String[] args) throws IOException, ScriptException, InterruptedException {
          ProcessBuilder pb = new ProcessBuilder().inheritIO().command("C:/Users/emon/Anaconda3/python.exe",
                  "forecast.py");
          Process process = pb.start();
          process.waitFor();
          InputStream inputStream = process.getInputStream();
  
          int i = 0;
          StringBuilder stringBuffer = new StringBuilder();
          while ((i = inputStream.read()) != -1) {
              stringBuffer.append((char) i);
          }
          System.out.println(stringBuffer.toString());
        }
  }
  </code></pre>
  
  <p>Basically, I used python script for forecasting some given time series data. I used facebook prophet to do that. In addition, I used Anaconda. So, in the <code>command</code> parenthesis, I used <code>C:/Users/emon/Anaconda3/python.exe</code>.</p>
  
  <pre><code>from fbprophet import Prophet
  import numpy as np
  import pandas as pd
  # import matplotlib.pyplot as plt
  
  # plt.rcParams['figure.figsize'] = (20, 10)
  # plt.style.use('ggplot')
  
  sales_df = pd.read_csv('multiTimeline.csv')
  sales_df['y_orig'] = sales_df['y']
  sales_df['y'] = np.log(sales_df['y'])
  model = Prophet()
  model.fit(sales_df)
  future_data = model.make_future_dataframe(periods=50, freq='w')
  forecast_data = model.predict(future_data)
  forecast_data[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
  model.plot(forecast_data)
  print(forecast_data)
  
  # for index, row in forecast_data.iterrows():
  #     print(
  #         str(index) + " " + str(row['ds']) + " " + str(np.exp(row['yhat'])) + " " + str(
  #             np.exp(row['yhat_lower'])) + " " + str(np.exp(row['yhat_upper'])))
  
  # plt.show()
  </code></pre>
  
  <p>When I run this python script separately, I get the expected output. But when I run it from java code it gives this error.</p>
  
  <pre><code>Traceback (most recent call last):
    File "google-trends-service/src/main/java/com/emon/forecast.py", line 1, in &lt;module&gt;
      from fbprophet import Prophet
    File "C:\Users\emon\Anaconda3\lib\site-packages\fbprophet\__init__.py", line 8, in &lt;module&gt;
      from fbprophet.forecaster import Prophet
    File "C:\Users\emon\Anaconda3\lib\site-packages\fbprophet\forecaster.py", line 15, in &lt;module&gt;
      import numpy as np
    File "C:\Users\emon\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in &lt;module&gt;
      from . import _distributor_init
    File "C:\Users\emon\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in &lt;module&gt;
      from. import _mklinit
  ImportError: DLL load failed: The specified module could not be found.
  </code></pre>
  
  <p>But if I replace my python script with only</p>
  
  <pre><code>print("Hello world")
  </code></pre>
  
  <p>This gives the expected output in the java console.</p>
  
  <p>I saw the previous posts but these did not solve my problem. Those are,</p>
  
  <p><a href="https://stackoverflow.com/questions/47304629/issue-while-calling-pythonanaconda-from-java">Issue while calling Python(Anaconda) from Java</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15263854/calling-python-script-from-java-mysqldb-imports">Calling Python script from JAVA MySQLdb imports</a></p>