I'm using pyenv to manage my python versions. When i use python 3.12.4 or python3.9^, i get this error:
File "src/pymssql/_pymssql.pyx", line 1, in init pymssql._pymssql
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pymssql/_mssql.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_bcp_batch'
my script:
from sqlalchemy import create_engine, text
import bi_pass
v_server = bi_pass.v_server
v_user = bi_pass.v_user
v_password = bi_pass.v_password
v_database = bi_pass.v_database
source_engine = create_engine(f"mssql+pymssql://{v_user}:{v_password}@{v_server}:1433/{v_database}")
source_conn = source_engine.connect()
query = text( """ SELECT * from test""")
result = source_conn.execute(query)
rows = result.fetchall()
source_conn.close()
source_engine.dispose()
I have a Mac m3 chip, how can I fix it?
Thanks
To resolve this issue, you need to install pymssql
using the following command:
pip install --no-binary :all: pymssql --no-cache --force
This error occurs because pymssql
relies on FreeTDS, and the precompiled binary may not be properly linked against it. Specifically, the _bcp_batch
function is expected in FreeTDS, but the installed pymssql
binary cannot find it.
By forcing a source installation (--no-binary :all:
), pip ensures that pymssql
is built specifically for your system, linking it properly against your installed version of FreeTDS.