Using Meta/Facebook Prophet with Conda/PyCall

Hi,

I run into problems when trying to run the example code from:

What I did:

import Pkg
ENV["PYTHON"]=""
Pkg.build("PyCall")

Restarted the Julia CLI, then:

import Pkg

Pkg.add("Conda")
using Conda
Conda.runconda(`update -y conda`)
Conda.add("pandas")
Conda.add("prophet")

and

julia> using Conda

julia> using PyCall

julia> pd = pyimport("pandas")
PyObject <module 'pandas' from '/home/ftournier/.julia/conda/3/x86_64/lib/python3.12/site-packages/pandas/__init__.py'>

julia> pro = pyimport("prophet")
Importing matplotlib failed. Plotting will not work.
Importing plotly failed. Interactive plots will not work.
PyObject <module 'prophet' from '/home/ftournier/.julia/conda/3/x86_64/lib/python3.12/site-packages/prophet/__init__.py'>

julia> m = pro.Prophet()
PyObject <prophet.forecaster.Prophet object at 0x7fd6beece6f0>

julia> df = pd.read_csv("https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv")
PyObject               ds          y
0     2007-12-10   9.590761
1     2007-12-11   8.519590
2     2007-12-12   8.183677
3     2007-12-13   8.072467
4     2007-12-14   7.893572
...          ...        ...
2900  2016-01-16   7.817223
2901  2016-01-17   9.273878
2902  2016-01-18  10.333775
2903  2016-01-19   9.125871
2904  2016-01-20   8.891374

[2905 rows x 2 columns]

Next step failed:

julia> m.fit(df)
14:55:24 - cmdstanpy - INFO - Chain [1] start processing
14:55:24 - cmdstanpy - INFO - Chain [1] done processing
14:55:24 - cmdstanpy - ERROR - Chain [1] error: error during processing Operation not permitted
Optimization terminated abnormally. Falling back to Newton.
14:55:24 - cmdstanpy - INFO - Chain [1] start processing
14:55:24 - cmdstanpy - INFO - Chain [1] done processing
14:55:24 - cmdstanpy - ERROR - Chain [1] error: error during processing Operation not permitted
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/jska/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) 
[15267] signal 11 (1): Segmentation fault
in expression starting at none:0
PyErr_CheckSignals at /usr/local/src/conda/python-3.12.11/Modules/signalmodule.c:1771 [inlined]
PyObject_Repr at /usr/local/src/conda/python-3.12.11/Objects/object.c:544
pystring at /home/jska/.julia/packages/PyCall/1gn3u/src/PyCall.jl:243
show at /home/jska/.julia/packages/PyCall/1gn3u/src/exception.jl:39
showerror at ./errorshow.jl:30 [inlined]
#showerror#1026 at ./errorshow.jl:97
showerror at ./errorshow.jl:95
unknown function (ip: 0x7f6b381018a2)
show_exception_stack at ./errorshow.jl:996
display_error at ./client.jl:117
jfptr_display_error_11782.1 at /opt/jska-tmp/julia-1.11.6/share/julia/compiled/v1.11/REPL/u0gqU_QBeOa.so (unknown line)
jl_apply at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
jl_f__call_latest at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/builtins.c:875
#invokelatest#2 at ./essentials.jl:1055 [inlined]
invokelatest at ./essentials.jl:1052 [inlined]
repl_display_error at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:414
print_response at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:431
#70 at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:405
jfptr_YY.70_10215.1 at /opt/jska-tmp/julia-1.11.6/share/julia/compiled/v1.11/REPL/u0gqU_QBeOa.so (unknown line)
with_repl_linfo at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:678
jfptr_with_repl_linfo_10303.1 at /opt/jska-tmp/julia-1.11.6/share/julia/compiled/v1.11/REPL/u0gqU_QBeOa.so (unknown line)
print_response at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:403
do_respond at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1037
jfptr_do_respond_10366.1 at /opt/jska-tmp/julia-1.11.6/share/julia/compiled/v1.11/REPL/u0gqU_QBeOa.so (unknown line)
jl_apply at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
jl_f__call_latest at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/builtins.c:875
#invokelatest#2 at ./essentials.jl:1055 [inlined]
invokelatest at ./essentials.jl:1052 [inlined]
#126 at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/REPL.jl:1444
jl_apply at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
jl_f__call_latest at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/builtins.c:875
#invokelatest#2 at ./essentials.jl:1055 [inlined]
invokelatest at ./essentials.jl:1052 [inlined]
#30 at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:1711
jfptr_YY.30_8323.1 at /opt/jska-tmp/julia-1.11.6/share/julia/compiled/v1.11/REPL/u0gqU_QBeOa.so (unknown line)
macro expansion at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2861 [inlined]
macro expansion at ./lock.jl:273 [inlined]
#282 at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/usr/share/julia/stdlib/v1.11/REPL/src/LineEdit.jl:2851
jfptr_YY.282_8870.1 at /opt/jska-tmp/julia-1.11.6/share/julia/compiled/v1.11/REPL/u0gqU_QBeOa.so (unknown line)
jl_apply at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
start_task at /cache/build/tester-amdci4-12/julialang/julia-release-1-dot-11/src/task.c:1202
Allocations: 1056136 (Pool: 1055206; Big: 930); GC: 2
Segmentation fault

I’m not familiar with using Python under Julia so I may have done something wrong.

Can you try PythonCall.jl instead? It is the more mature way to call Python from Julia, PyCall.jl was an earlier package with less robust design.

In this specific case, I think you might be running into threading issues like thread safety Β· Issue #882 Β· JuliaPy/PyCall.jl Β· GitHub

2 Likes

I managed to install PythonCall, but I still have an error:

julia> using CondaPkg

julia> using PythonCall

julia> CondaPkg.add("Pandas")
    CondaPkg Found dependencies: /home/jska/.julia/environments/v1.11/CondaPkg.toml
    CondaPkg Found dependencies: /home/jska/.julia/packages/PythonCall/avYrV/CondaPkg.toml
    CondaPkg Initialising pixi
             β”‚ /home/jska/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi
             β”‚ init
             β”‚ --format pixi
             β”” /home/jska/.julia/environments/v1.11/.CondaPkg
Created /home/jska/.julia/environments/v1.11/.CondaPkg/pixi.toml
    CondaPkg Wrote /home/jska/.julia/environments/v1.11/.CondaPkg/pixi.toml
             β”‚ [dependencies]
             β”‚ openssl = ">=3, <3.6"
             β”‚ prophet = "*"
             β”‚ libstdcxx-ng = ">=3.4,<14.0"
             β”‚ pandas = "*"
             β”‚ 
             β”‚     [dependencies.python]
             β”‚     channel = "conda-forge"
             β”‚     build = "*cp*"
             β”‚     version = ">=3.8,<4"
             β”‚ 
             β”‚ [project]
             β”‚ name = ".CondaPkg"
             β”‚ platforms = ["linux-64"]
             β”‚ channels = ["conda-forge"]
             β”‚ channel-priority = "strict"
             β”” description = "automatically generated by CondaPkg.jl"
    CondaPkg Installing packages
             β”‚ /home/jska/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi
             β”‚ install
             β”” --manifest-path /home/jska/.julia/environments/v1.11/.CondaPkg/pixi.toml
The default environment has been installed.

julia> CondaPkg.add("prophet")

julia> pd = pyimport("pandas")
Python: <module 'pandas' from '/home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/pandas/__init__.py'>

julia> pro = pyimport("prophet")
Importing matplotlib failed. Plotting will not work.
Importing plotly failed. Interactive plots will not work.
Python: <module 'prophet' from '/home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/__init__.py'>

julia> df = pd.read_csv("https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv")
Python:
              ds          y
0     2007-12-10   9.590761
1     2007-12-11   8.519590
2     2007-12-12   8.183677
3     2007-12-13   8.072467
4     2007-12-14   7.893572
...          ...        ...
2900  2016-01-16   7.817223
2901  2016-01-17   9.273878
2902  2016-01-18  10.333775
2903  2016-01-19   9.125871
2904  2016-01-20   8.891374

[2905 rows x 2 columns]

julia> m = pro.Prophet()
Python: <prophet.forecaster.Prophet object at 0x7f02760b2a50>

julia> m.fit(df)
17:55:06 - cmdstanpy - INFO - Chain [1] start processing
17:55:06 - cmdstanpy - INFO - Chain [1] done processing
17:55:06 - cmdstanpy - ERROR - Chain [1] error: error during processing Operation not permitted
Optimization terminated abnormally. Falling back to Newton.
17:55:06 - cmdstanpy - INFO - Chain [1] start processing
17:55:06 - cmdstanpy - INFO - Chain [1] done processing
17:55:06 - cmdstanpy - ERROR - Chain [1] error: error during processing Operation not permitted
ERROR: Python: RuntimeError: Error during optimization! Command '/home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/stan_model/prophet_model.bin random seed=15412 data file=/tmp/tmp5863norm/6uej5bsv.json init=/tmp/tmp5863norm/1dp0uqpj.json output file=/tmp/tmp5863norm/prophet_model1pgmslsi/prophet_model-20250901175506.csv method=optimize algorithm=newton iter=10000' failed: console log output:

/home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/stan_model/prophet_model.bin: /home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/stan_model/../../../../libstdc++.so.6: version `CXXABI_1.3.15' not found (required by /home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/stan_model/../../../../libtbb.so.12)

Python stacktrace:
 [1] optimize
   @ cmdstanpy.model ~/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/cmdstanpy/model.py:659
 [2] fit
   @ prophet.models ~/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/models.py:128
 [3] fit
   @ prophet.forecaster ~/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/forecaster.py:1232
Stacktrace:
 [1] pythrow()
   @ PythonCall.Core ~/.julia/packages/PythonCall/avYrV/src/Core/err.jl:89
 [2] errcheck
   @ ~/.julia/packages/PythonCall/avYrV/src/Core/err.jl:10 [inlined]
 [3] pycallargs(f::Py, args::Py)
   @ PythonCall.Core ~/.julia/packages/PythonCall/avYrV/src/Core/builtins.jl:220
 [4] pycall(::Py, ::Py, ::Vararg{Py}; kwargs::@Kwargs{})
   @ PythonCall.Core ~/.julia/packages/PythonCall/avYrV/src/Core/builtins.jl:243
 [5] pycall(::Py, ::Py, ::Vararg{Py})
   @ PythonCall.Core ~/.julia/packages/PythonCall/avYrV/src/Core/builtins.jl:233
 [6] (::Py)(::Py, ::Vararg{Py}; kwargs::@Kwargs{})
   @ PythonCall.Core ~/.julia/packages/PythonCall/avYrV/src/Core/Py.jl:362
 [7] top-level scope
   @ REPL[9]:1

It looks like you are on a slightly outdated version of PythonCall, please update to the latest version (0.9.27) and try again, which should fix that CXX ABI error you’re getting.

2 Likes

Thanks.
It’s better, although I run into a segfault at some point:

julia> using CondaPkg

julia> using PythonCall

julia> CondaPkg.add("Pandas")
    CondaPkg Found dependencies: /home/jska/.julia/environments/v1.11/CondaPkg.toml
    CondaPkg Found dependencies: /home/jska/.julia/packages/PythonCall/IOKTD/CondaPkg.toml
    CondaPkg Initialising pixi
             β”‚ /home/jska/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi
             β”‚ init
             β”‚ --format pixi
             β”” /home/jska/.julia/environments/v1.11/.CondaPkg
Created /home/jska/.julia/environments/v1.11/.CondaPkg/pixi.toml
    CondaPkg Wrote /home/jska/.julia/environments/v1.11/.CondaPkg/pixi.toml
             β”‚ [dependencies]
             β”‚ openssl = ">=3, <3.6"
             β”‚ libstdcxx = ">=3.4,<14.0"
             β”‚ prophet = "*"
             β”‚ libstdcxx-ng = ">=3.4,<14.0"
             β”‚ pandas = "*"
             β”‚ 
             β”‚     [dependencies.python]
             β”‚     channel = "conda-forge"
             β”‚     build = "*cp*"
             β”‚     version = ">=3.9,<4"
             β”‚ 
             β”‚ [project]
             β”‚ name = ".CondaPkg"
             β”‚ platforms = ["linux-64"]
             β”‚ channels = ["conda-forge"]
             β”‚ channel-priority = "strict"
             β”” description = "automatically generated by CondaPkg.jl"
    CondaPkg Installing packages
             β”‚ /home/jska/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi
             β”‚ install
             β”” --manifest-path /home/jska/.julia/environments/v1.11/.CondaPkg/pixi.toml
The default environment has been installed.

julia> CondaPkg.add("prophet")

julia> pd = pyimport("pandas")
Python: <module 'pandas' from '/home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/pandas/__init__.py'>

julia> pro = pyimport("prophet")
Importing plotly failed. Interactive plots will not work.
Python: <module 'prophet' from '/home/jska/.julia/environments/v1.11/.CondaPkg/.pixi/envs/default/lib/python3.13/site-packages/prophet/__init__.py'>

julia> df = pd.read_csv("https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv")
Python:
              ds          y
0     2007-12-10   9.590761
1     2007-12-11   8.519590
2     2007-12-12   8.183677
3     2007-12-13   8.072467
4     2007-12-14   7.893572
...          ...        ...
2900  2016-01-16   7.817223
2901  2016-01-17   9.273878
2902  2016-01-18  10.333775
2903  2016-01-19   9.125871
2904  2016-01-20   8.891374

[2905 rows x 2 columns]

julia> m = pro.Prophet()
Python: <prophet.forecaster.Prophet object at 0x7fa7b5f50d70>

julia> m.fit(df)
14:56:04 - cmdstanpy - INFO - Chain [1] start processing
14:56:05 - cmdstanpy - INFO - Chain [1] done processing
Python: <prophet.forecaster.Prophet object at 0x7fa7b5f50d70>

julia> future = m.make_future_dataframe(periods=365)
Python:
             ds
0    2007-12-10
1    2007-12-11
2    2007-12-12
3    2007-12-13
4    2007-12-14
...         ...
3265 2017-01-15
3266 2017-01-16
3267 2017-01-17
3268 2017-01-18
3269 2017-01-19

[3270 rows x 1 columns]

julia> future.tail()
Python:
             ds
3265 2017-01-15
3266 2017-01-16
3267 2017-01-17
3268 2017-01-18
3269 2017-01-19

julia> forecast = m.predict(future)
Python:
             ds     trend  yhat_lower  ...  multiplicative_terms_lower  multiplicative_terms_upper      yhat
0    2007-12-10  8.032685    8.186324  ...                         0.0                         0.0  8.835804
1    2007-12-11  8.031171    7.931609  ...                         0.0                         0.0  8.584401
2    2007-12-12  8.029657    7.717716  ...                         0.0                         0.0  8.380341
3    2007-12-13  8.028143    7.731661  ...                         0.0                         0.0  8.358290
4    2007-12-14  8.026629    7.754926  ...                         0.0                         0.0  8.346369
...         ...       ...         ...  ...                         ...                         ...       ...
3265 2017-01-15  7.183420    7.472450  ...                         0.0                         0.0  8.201841
3266 2017-01-16  7.182385    7.761344  ...                         0.0                         0.0  8.526815
3267 2017-01-17  7.181351    7.580981  ...                         0.0                         0.0  8.314183
3268 2017-01-18  7.180316    7.428009  ...                         0.0                         0.0  8.146813
3269 2017-01-19  7.179281    7.398712  ...                         0.0                         0.0  8.158682

[3270 rows x 19 columns]

julia> forecast[["ds", "yhat", "yhat_lower", "yhat_upper"]].tail()
ERROR: Python: 
[17017] signal 11 (1): Segmentation fault
in expression starting at none:0
_PyErr_NormalizeException at /usr/local/src/conda/python-3.13.5/Python/errors.c:385
unknown function (ip: 0x7fa815bbe2df)
Allocations: 17105245 (Pool: 17102116; Big: 3129); GC: 20
Segmentation fault

Everything looks very unstable when I load PythonCall, even with 1 thread:

julia> using PythonCall
ERROR: InitError: Python: SystemError: initialization of _datetime did not return an extension module
Python stacktrace:
 [1] <module>
   @ 
SYSTEM (REPL): showing an error caused an error
ERROR: Python: 
SYSTEM (REPL): caught exception of type PyException while trying to handle a nested exception; giving up

These segfaults and system errors are very strange. It seems like the python installation is corrupted or something.

Do you have any relevant environment variables set? Can you list any containing PYTHON or JULIA or LD_LIBRARY_PATH or anything else that looks potentially relevant?

Also try the following in the same project to check if the python installation is ok:

CondaPkg.withenv() do
    run(`python`)
end

May be linked to my mix of PyCall and PythonCall, see:

https://discourse.julialang.org/t/cant-build-pythoncall/

julia> CondaPkg.withenv() do
           run(`python`)
       end
Python 3.12.11 | packaged by conda-forge | (main, Jun  4 2025, 14:45:31) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Yes makes sense. If you start a fresh Julia session and run your earlier examples without loading PyCall at all, do they work ok?

A bit off-topic (since this isn’t PyCall-related), but here’s an alternative way
to use Prophet from Julia if nothing else works.

Instead of embedding Python inside Julia via the Python C API (like PyCall or
PythonCall), Rembus.jl communicates with Python at the message-passing level (sockets).

That means you can run Prophet inside a pure Python server process, and call it
from Julia as a client β€” no shared runtimes, just RPC-style communication.

Python server (forecast-server.py)

import pandas as pd
from prophet import Prophet
import rembus


def forecast(file):
    df = pd.read_csv(file)
    m = Prophet()
    m.fit(df)
    future = m.make_future_dataframe(periods=365)
    fcast = m.predict(future)
    return fcast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']]


# Serve RPC requests on port 8000
rb = rembus.node(port=8000)

rb.expose(forecast)
rb.wait()

Julia client

using Rembus

filename = "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"

rb = component("julia-client")
df = rpc(rb, "forecast", filename)

This way, Julia and Python processes remain independent and cooperate
through Rembus.

2 Likes