How to fix ARM mach-o file compatibility error when importing prophet module on python 3.9?

196 Views Asked by At

When running my file, I get an error saying /Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/cryptography/hazmat/bindings/_rust.abi3.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

import streamlit as st
from datetime import date

import yfinance as yf
from fbprophet import Prophet
from fbprophet.plot import plot_plotly
from plotly import graph_objs as go

START = "2015-01-01"
TODAY = date.today().strftime("%Y-%m-%d")

st.title('Stock Forecast App')

stocks = ('GOOG', 'AAPL', 'MSFT', 'GME')
selected_stock = st.selectbox('Select dataset for prediction', stocks)

n_years = st.slider('Years of prediction:', 1, 4)
period = n_years * 365


@st.cache
def load_data(ticker):
    data = yf.download(ticker, START, TODAY)
    data.reset_index(inplace=True)
    return data

    
data_load_state = st.text('Loading data...')
data = load_data(selected_stock)
data_load_state.text('Loading data... done!')

st.subheader('Raw data')
st.write(data.tail())

# Plot raw data
def plot_raw_data():
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=data['Date'], y=data['Open'], name="stock_open"))
    fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], name="stock_close"))
    fig.layout.update(title_text='Time Series data with Rangeslider', xaxis_rangeslider_visible=True)
    st.plotly_chart(fig)
    
plot_raw_data()

# Predict forecast with Prophet.
df_train = data[['Date','Close']]
df_train = df_train.rename(columns={"Date": "ds", "Close": "y"})

m = Prophet()
m.fit(df_train)
future = m.make_future_dataframe(periods=period)
forecast = m.predict(future)

# Show and plot forecast
st.subheader('Forecast data')
st.write(forecast.tail())
    
st.write(f'Forecast plot for {n_years} years')
fig1 = plot_plotly(m, forecast)
st.plotly_chart(fig1)

st.write("Forecast components")
fig2 = m.plot_components(forecast)
st.write(fig2)
type hereTraceback (most recent call last):
  File "/Users/srijan/Code/PP/stockpredictor3.py", line 4, in <module>
    import yfinance as yf
  File "/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/yfinance/__init__.py", line 23, in <module>
    from .ticker import Ticker
  File "/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/yfinance/ticker.py", line 29, in <module>
    from .base import TickerBase
  File "/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/yfinance/base.py", line 32, in <module>
    from .data import TickerData
  File "/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/yfinance/data.py", line 12, in <module>
    from cryptography.hazmat.primitives import padding
  File "/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/cryptography/hazmat/primitives/padding.py", line 11, in <module>
    from cryptography.hazmat.bindings._rust import (
ImportError: dlopen(/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/cryptography/hazmat/bindings/_rust.abi3.so, 0x0002): tried: '/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/cryptography/hazmat/bindings/_rust.abi3.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/cryptography/hazmat/bindings/_rust.abi3.so' (no such file), '/Users/srijan/miniforge3/envs/PersonalProject/lib/python3.9/site-packages/cryptography/hazmat/bindings/_rust.abi3.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I tried lots of things like downgrading python, reinstalling all my dependencies but nothing works, the error keeps popping up.

1

There are 1 best solutions below

0
On

Run it on x86 . Some of the dependencies clearly don't support ARM architecture.