mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.94k stars 562 forks source link

PYODBC - Won't create connection in Anaconda3 (Python 3.6) #234

Closed MaximoTrinidad closed 3 years ago

MaximoTrinidad commented 7 years ago

Please first make sure you have looked at:

Environment

Windows WSL Bash

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

Issue

Although I was able to install the pyodbc package in Anaconda3, and the "import pyodbc" module load without any errors. But, the connection string line error-out giving the following error:

maxt@MTrinidadLT2:~$ python Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. import pyodbc cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=MTRINIDADLT2,51417;DATABASE=master;UID=sa;PWD=$SqlPwd01!') Traceback (most recent call last): File "", line 1, in pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.7.0' : file not found (0) (SQLDriverConnect)")

error_pyodbc_01_2017-05-02_8-50-56 error_pyodbc_02_2017-05-02_8-50-56

Often it is easiest to describe your issue as "expected behavior" and "observed behavior".

gordthompson commented 7 years ago

Your screenshot indicates that you are using pyodbc 3.0.10. Consider trying the most recent version (currently 4.0.16) before requesting help.

Also, as suggested in your earlier issue here, try doing a setup in an actual Ubuntu 16.04 virtual machine to help determine if this is an issue specific to working in the WSL Bash environment.

MaximoTrinidad commented 7 years ago

Hi @gordthompson,

Just an FYI

When I'm setting up any of my Ubuntu (or WSL) environments I typically use the following command for installing PYODBC in for Python 3.5:

pip3 install pyodbc

Excuse my lack of Linux experience as I thought the command will installed the latest version. That's why possibly I'm downloading the wrong version.

What's the correct format to grab the latest version? Something like "pip3 install pyodbc-x-x-x" (?).

I appreciate the help!

By the way, in Windows, Anaconda is working! After reading your comment. I did the following Anaconda command in Windows:

conda list pyodbc

Results confirms both version 3.0.10 and 4.0.16 are loaded:

PS C:\WINDOWS\system32> conda list pyodbc

packages in environment at C:\Program Files\Anaconda3:

# pyodbc 3.0.10 py36_1 pyodbc 4.0.16

I will try to do the longer route with 4.0.16 then see how it goes.

Thanks, :)

MaximoTrinidad commented 7 years ago

I forgot to mention that I got everything working on Python 3.5. The issue is with Anaconda in Ubuntu Linux!

gordthompson commented 7 years ago

So you've got Anaconda installed under native Windows and are trying to work with it from within WSL Bash. And, from the Windows (PowerShell) side, conda list pyodbc tells you that both 3.0.10 and 4.0.16 are installed. That's... odd.

In any case, from the WSL Bash command prompt, what do you see when you try to list the contents of /opt? Do you see a microsoft directory? If you follow it down can you see the file that is supposedly missing?

Also, from within Python under WSL Bash, after you import pyodbc what does pyodbc.version say?

gordthompson commented 7 years ago

Also, I see from

https://anaconda.org/anaconda/pyodbc

that it says to use

conda install -c anaconda pyodbc=3.0.10

which might explain why you have an old version. I know that pip is aware of new pyodbc releases but I don't know if @mkleehammer would have to jump through extra hooops to keep conda up-to-date, too.

MaximoTrinidad commented 7 years ago

The only reason I'm venturing on using pyodbc is due to the announcement of SQL Server 2017 integrating Python 3.6 (Anaconda). I already got my Python 3.5.2 working. And, Anaconda in Windows works with pyodbc. Only the Linux piece I haven't solved yet.

By the way I just downloaded the latest version but I can't find any instructions on How-to installed it. Sorry again for my lack of Linux experience. I'm use to do the ("configure", "make", and "install") when I can find it. :)

Any tip??

Thanks again!

MaximoTrinidad commented 7 years ago

Sorry @gordthompson! Answer to your question: ".. In any case, from the WSL Bash command prompt, what do you see when you try to list the contents of /opt? Do you see a microsoft directory? If you follow it down can you see the file that is supposedly missing? .."

Yes, I see both the Microsoft directory and the file. And, I'm having the same problem in Ubuntu 16.04. :)

MaximoTrinidad commented 7 years ago

@gordthompson

TRUE!!

folder_exist_2017-05-03_20-56-51

MaximoTrinidad commented 7 years ago

Here's the same error in Ubuntu 16.04.2

pyodbc_anaconda_err

gordthompson commented 7 years ago

Does your Python app have read permissions on the file? i.e., does

print(os.access('/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.7.0', os.R_OK))

print True?

meet-bhagdev commented 7 years ago

Does this help?

https://github.com/ContinuumIO/anaconda-issues/issues/1639

MaximoTrinidad commented 7 years ago

@gordthompson!

I do have permission.

import os print(os.access('/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.7.0', os.R_OK)) True

MaximoTrinidad commented 7 years ago

Hi @meet-bhagdev ,

Forgive me, I looked at the link but I still not too advance on Linux. So, if possible, what's the steps to make it work?? I would love to test this resolution.

:)

MaximoTrinidad commented 7 years ago

Errr!! I forgot to ask... What about the resolution for Windows Anaconda?

meet-bhagdev commented 7 years ago

@MaximoTrinidad Windows Anaconda should work. These instructions work for me: https://www.continuum.io/blog/developer-blog/anaconda-easy-button-microsoft-sql-server-and-python. Once the Anaconda issue resolves iil write up the steps up for Linux 👍

MaximoTrinidad commented 7 years ago

Thanks @meet-bhagdev!

I will give it a try. :)

MaximoTrinidad commented 7 years ago

Shut! I don't know what's wrong with my installation. In both Windows, WSL, and Ubuntu 16.04.2.

I've done what's on the blog before and is not working for me.

In Linux, error:

import pyodbc Traceback (most recent call last): File "", line 1, in ImportError: /home/maxt/anaconda3/lib/python3.6/site-packages/pyodbc.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PySlice_Unpack

In Windows, error:

import pyodbc Traceback (most recent call last): File "", line 1, in ImportError: DLL load failed: The specified procedure could not be found.

Conda platform : linux-64 | conda version : 4.3.18 platform : win-64 | conda version : 4.3.18

PyODBC - Conda Linux: python 3.5 and 3.6 | unixodbc 2.3.4 Conda Windows python 3.5 and 3.6 (SQL Drivers are installed)

:(

nehaljwani commented 7 years ago

@MaximoTrinidad Try updating python to something > 3.6.0=0


(py36) root@75eb43ff7f79:~$ conda list | grep -e python -e pyodbc -e unixodbc
pyodbc                    4.0.16                   py36_0
python                    3.6.0                         0
unixodbc                  2.3.4                         0

(py36) root@75eb43ff7f79:~$ python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import pyodbc
ImportError: /conda/envs/py36/lib/python3.6/site-packages/pyodbc.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PySlice_Unpack

(py36) root@75eb43ff7f79:~$ conda update python
Fetching package metadata .........
Solving package specifications: .

Package plan for installation in environment /conda/envs/py36:

The following packages will be UPDATED:

    python: 3.6.0-0 --> 3.6.1-2

Proceed ([y]/n)?

(py36) root@75eb43ff7f79:~$ python test.py
Reading data from table
Microsoft SQL Server vNext (CTP2.0) - 14.0.500.272 (X64)
        Apr 13 2017 11:44:40
        Copyright (C) 2017 Microsoft Corporation. All rights reserved.
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.2 LTS)
nehaljwani commented 7 years ago

@MaximoTrinidad Also, make sure libgcc is >= 5.1

conda update libgcc
MaximoTrinidad commented 7 years ago

@nehaljwani,

Hum! is not on Conda:

PS C:\Program Files\PowerShell\6.0.0-beta.1> conda info libgcc Fetching package metadata ...........

NoPackagesFoundError: Package missing in current win-64 channels:

PS C:\Program Files\PowerShell\6.0.0-beta.1>

nehaljwani commented 7 years ago

@MaximoTrinidad That was for WSL. For Windows, I will check back and reply.

MaximoTrinidad commented 7 years ago

Thanks @nehaljwani!

Got it on WSL!

maxt@MTrinidadLT2:~$ conda update libgcc Fetching package metadata ......... Solving package specifications: .

Package plan for installation in environment /home/maxt/anaconda3:

The following packages will be UPDATED:

anaconda: 4.3.1-np111py36_0 --> custom-py36_0
libgcc:   4.8.5-2           --> 5.2.0-0      

Proceed ([y]/n)? y

libgcc-5.2.0-0 100% |################################| Time: 0:00:00 4.91 MB/s

maxt@MTrinidadLT2:~$ maxt@MTrinidadLT2:~$ python Python 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information.

import pyodbc Traceback (most recent call last): File "", line 1, in ImportError: /home/maxt/anaconda3/lib/python3.6/site-packages/pyodbc.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PySlice_Unpack exit()

I try the other steps:

maxt@MTrinidadLT2:~$ maxt@MTrinidadLT2:~$ conda list | grep -e python -e pyodbc -e unixodbc ipython 5.1.0 py36_0
ipython_genutils 0.1.0 py36_0
pyodbc 4.0.16 py36_0
pyodbc 4.0.16 python 3.6.0 0
python-dateutil 2.6.0 py36_0
unixodbc 2.3.4 0
maxt@MTrinidadLT2:~$ maxt@MTrinidadLT2:~$ conda update python Fetching package metadata ......... Solving package specifications: .

Package plan for installation in environment /home/maxt/anaconda3:

The following packages will be UPDATED:

python: 3.6.0-0 --> 3.6.1-2

Proceed ([y]/n)? y

python-3.6.1-2 100% |################################| Time: 0:00:00 17.28 MB/s

Thanks!! I works on WSL.

if cursor.execute(tsql): ... row = cursor.fetchone() ... while row: ... print(str(row[0]) + " " + str(row[1])) ... row = cursor.fetchone() ... Eduardo Santiago Florida Alisson Perez New York MySQL2K16A Instance2

Hurray! Now I need Windows to work. :)

MaximoTrinidad commented 7 years ago

I truly think that including the package pyodbc, or similar variation, in Anaconda will bring some benefits with SQL Server running it as External Stored-procedure connecting to data tables.
:)

nehaljwani commented 7 years ago

@MaximoTrinidad In the anaconda environment where import pyodbc fails on win-64, please type conda list -ec and share the output as an attachment with a comment.

MaximoTrinidad commented 7 years ago

Thanks @nehaljwani! See below.

PS C:\Program Files\PowerShell\6.0.0-beta.1> python Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import pyodbc Traceback (most recent call last): File "", line 1, in ImportError: DLL load failed: The specified procedure could not be found. exit() PS C:\Program Files\PowerShell\6.0.0-beta.1> conda list -ec defaults::_license-1.1-py36_1 defaults::alabaster-0.7.9-py36_0 defaults::anaconda-4.3.1-np111py36_0 defaults::anaconda-client-1.6.0-py36_0 defaults::anaconda-navigator-1.5.0-py36_0 defaults::anaconda-project-0.4.1-py36_0 defaults::astroid-1.4.9-py36_0 defaults::astropy-1.3-np111py36_0 defaults::babel-2.3.4-py36_0 defaults::backports-1.0-py36_0 defaults::beautifulsoup4-4.5.3-py36_0 defaults::bitarray-0.8.1-py36_1 defaults::blaze-0.10.1-py36_0 defaults::bokeh-0.12.4-py36_0 defaults::boto-2.45.0-py36_0 defaults::bottleneck-1.2.0-np111py36_0 defaults::bzip2-1.0.6-vc14_3 defaults::cffi-1.9.1-py36_0 defaults::chardet-2.3.0-py36_0 defaults::chest-0.2.3-py36_0 defaults::click-6.7-py36_0 defaults::cloudpickle-0.2.2-py36_0 defaults::clyent-1.2.2-py36_0 defaults::colorama-0.3.7-py36_0 defaults::comtypes-1.1.2-py36_0 defaults::conda-4.3.18-py36_0 defaults::conda-env-2.6.0-0 defaults::configobj-5.0.6-py36_0 defaults::console_shortcut-0.1.1-py36_1 defaults::contextlib2-0.5.4-py36_0 defaults::cryptography-1.7.1-py36_0 defaults::curl-7.52.1-vc14_0 defaults::cycler-0.10.0-py36_0 defaults::cython-0.25.2-py36_0 defaults::cytoolz-0.8.2-py36_0 defaults::dask-0.13.0-py36_0 defaults::datashape-0.5.4-py36_0 defaults::decorator-4.0.11-py36_0 defaults::dill-0.2.5-py36_0 defaults::docutils-0.13.1-py36_0 defaults::entrypoints-0.2.2-py36_0 defaults::et_xmlfile-1.0.1-py36_0 defaults::fastcache-1.0.2-py36_1 defaults::flask-0.12-py36_0 defaults::flask-cors-3.0.2-py36_0 defaults::freetype-2.5.5-vc14_2 defaults::get_terminal_size-1.0.0-py36_0 defaults::gevent-1.2.1-py36_0 defaults::greenlet-0.4.11-py36_0 defaults::h5py-2.6.0-np111py36_2 defaults::hdf5-1.8.15.1-vc14_4 defaults::heapdict-1.0.0-py36_1 defaults::icu-57.1-vc14_0 defaults::idna-2.2-py36_0 defaults::imagesize-0.7.1-py36_0 defaults::ipykernel-4.5.2-py36_0 defaults::ipython-5.1.0-py36_0 defaults::ipython_genutils-0.1.0-py36_0 defaults::ipywidgets-5.2.2-py36_1 defaults::isort-4.2.5-py36_0 defaults::itsdangerous-0.24-py36_0 defaults::jdcal-1.3-py36_0 defaults::jedi-0.9.0-py36_1 defaults::jinja2-2.9.4-py36_0 defaults::jpeg-9b-vc14_0 defaults::jsonschema-2.5.1-py36_0 defaults::jupyter-1.0.0-py36_3 defaults::jupyter_client-4.4.0-py36_0 defaults::jupyter_console-5.0.0-py36_0 defaults::jupyter_core-4.2.1-py36_0 defaults::lazy-object-proxy-1.2.2-py36_0 defaults::libpng-1.6.27-vc14_0 defaults::libtiff-4.0.6-vc14_3 defaults::llvmlite-0.15.0-py36_0 defaults::locket-0.2.0-py36_1 defaults::lxml-3.7.2-py36_0 defaults::m2-gcc-libs-5.3.0-4 defaults::m2-libgc-7.2.d-2 defaults::m2-msys2-runtime-2.5.0.17080.65c939c-3 defaults::markupsafe-0.23-py36_2 defaults::matplotlib-2.0.0-np111py36_0 defaults::menuinst-1.4.4-py36_0 defaults::mistune-0.7.3-py36_0 defaults::mkl-2017.0.1-0 defaults::mkl-service-1.1.2-py36_3 defaults::mpmath-0.19-py36_1 defaults::msys2-conda-epoch-20160418-1 defaults::multipledispatch-0.4.9-py36_0 defaults::nbconvert-4.2.0-py36_0 defaults::nbformat-4.2.0-py36_0 defaults::networkx-1.11-py36_0 defaults::nltk-3.2.2-py36_0 defaults::nose-1.3.7-py36_1 defaults::notebook-4.3.1-py36_2 defaults::numba-0.30.1-np111py36_0 defaults::numexpr-2.6.1-np111py36_2 defaults::numpy-1.11.3-py36_0 defaults::numpydoc-0.6.0-py36_0 defaults::odo-0.5.0-py36_1 defaults::openpyxl-2.4.1-py36_0 defaults::openssl-1.0.2k-vc14_0 defaults::pandas-0.19.2-np111py36_1 defaults::partd-0.3.7-py36_0 defaults::path.py-10.0-py36_0 defaults::pathlib2-2.2.0-py36_0 defaults::patsy-0.4.1-py36_0 defaults::pep8-1.7.0-py36_0 defaults::pickleshare-0.7.4-py36_0 defaults::pillow-4.0.0-py36_0 defaults::pip-9.0.1-py36_1 defaults::ply-3.9-py36_0 defaults::prompt_toolkit-1.0.9-py36_0 defaults::psutil-5.0.1-py36_0 defaults::py-1.4.32-py36_0 defaults::pyasn1-0.1.9-py36_0 defaults::pycosat-0.6.1-py36_1 defaults::pycparser-2.17-py36_0 defaults::pycrypto-2.6.1-py36_5 defaults::pycurl-7.43.0-py36_2 defaults::pyflakes-1.5.0-py36_0 defaults::pygments-2.1.3-py36_0 defaults::pylint-1.6.4-py36_1 defaults::pyodbc-4.0.16-py36_0 defaults::pyopenssl-16.2.0-py36_0 defaults::pyparsing-2.1.4-py36_0 defaults::pyqt-5.6.0-py36_2 defaults::pytables-3.2.2-np111py36_4 defaults::pytest-3.0.5-py36_0 defaults::python-3.6.0-0 defaults::python-dateutil-2.6.0-py36_0 defaults::pytz-2016.10-py36_0 defaults::pywin32-220-py36_2 defaults::pyyaml-3.12-py36_0 defaults::pyzmq-16.0.2-py36_0 defaults::qt-5.6.2-vc14_3 defaults::qtawesome-0.4.3-py36_0 defaults::qtconsole-4.2.1-py36_2 defaults::qtpy-1.2.1-py36_0 defaults::requests-2.12.4-py36_0 defaults::rope-0.9.4-py36_1 defaults::ruamel_yaml-0.11.14-py36_1 defaults::scikit-image-0.12.3-np111py36_1 defaults::scikit-learn-0.18.1-np111py36_1 defaults::scipy-0.18.1-np111py36_1 defaults::seaborn-0.7.1-py36_0 defaults::setuptools-27.2.0-py36_1 defaults::simplegeneric-0.8.1-py36_1 defaults::singledispatch-3.4.0.3-py36_0 defaults::sip-4.18-py36_0 defaults::six-1.10.0-py36_0 defaults::snowballstemmer-1.2.1-py36_0 defaults::sockjs-tornado-1.0.3-py36_0 defaults::sphinx-1.5.1-py36_0 defaults::spyder-3.1.2-py36_0 defaults::sqlalchemy-1.1.5-py36_0 defaults::statsmodels-0.6.1-np111py36_1 defaults::sympy-1.0-py36_0 defaults::tk-8.5.18-vc14_0 defaults::toolz-0.8.2-py36_0 defaults::tornado-4.4.2-py36_0 defaults::traitlets-4.3.1-py36_0 defaults::unicodecsv-0.14.1-py36_0 defaults::vs2015_runtime-14.0.25123-0 defaults::wcwidth-0.1.7-py36_0 defaults::werkzeug-0.11.15-py36_0 defaults::wheel-0.29.0-py36_0 defaults::widgetsnbextension-1.2.6-py36_0 defaults::win_unicode_console-0.5-py36_0 defaults::wrapt-1.10.8-py36_0 defaults::xlrd-1.0.0-py36_0 defaults::xlsxwriter-0.9.6-py36_0 defaults::xlwings-0.10.2-py36_0 defaults::xlwt-1.2.0-py36_0 defaults::zlib-1.2.8-vc14_3 PS C:\Program Files\PowerShell\6.0.0-beta.1>

:)

nehaljwani commented 7 years ago

@MaximoTrinidad Thanks for sharing this. I was able to reproduce this:

(234) nwani@speedforce C:\Users\nwani\Downloads>conda list -f python                                                  
# packages in environment at C:\Users\nwani\Miniconda3\envs\234:                                                        
#                                                                                                                       
python                    3.6.0                         0                                                               

(234) nwani@speedforce C:\Users\nwani\Downloads>python -c "import pyodbc; print(pyodbc.__file__)"                     
Traceback (most recent call last):                                                                                      
  File "<string>", line 1, in <module>                                                                                  
ImportError: DLL load failed: The specified procedure could not be found.                                               

The fix is simple. Upgrade to python >= 3.6.1

(234) nwani@speedforce C:\Users\nwani\Downloads>conda install python=3.6.1                                            
Fetching package metadata ...........                                                                                   
Solving package specifications: .                                                                                       

Package plan for installation in environment C:\Users\nwani\Miniconda3\envs\234:                                        

The following packages will be UPDATED:                                                                                 

    python: 3.6.0-0 --> 3.6.1-2                                                                                         

Proceed ([y]/n)? y                                                                                                      

(234) nwani@speedforce C:\Users\nwani\Downloads>python -c "import pyodbc; print(pyodbc.__file__)"                     
C:\Users\nwani\Miniconda3\envs\234\lib\site-packages\pyodbc.cp36-win_amd64.pyd  

To find out why the import was failing, I ran the profiler provided in the program dependency walker in Windows and this is what I found:

screenshot from 2017-05-27 18-45-52

As seems evident, the symbol 'PySlice_AdjustIndices' seemed to be missing in the python3.6.dll file. This lead me to https://mail.python.org/pipermail/python-dev/2017-March/147707.html , https://bugzilla.redhat.com/show_bug.cgi?id=1435135 and finally https://bugs.python.org/issue29943 . The end solution seems to be to update python to 3.6.1

MaximoTrinidad commented 7 years ago

That's Awesome @nehaljwani!!

So I should update to Python 3.6.1 in both Windows and Linux? Or, only Windows?

This is thing! I already try using Anaconda in SQL Server but I want to try using pyodbc in it. I can see people using in T-SQL scripts.

:)

nehaljwani commented 7 years ago

@MaximoTrinidad Yes, please update python to >= 3.6.1 in Linux as well as Windows.

MaximoTrinidad commented 7 years ago

Woohoo!! Yes!!

So, from Anaconda, you install Python 3.6.0, then you can run the command: conda upgrade python

This will upgrade Python from 3.6.0 to 3.6.1. Then, I did the conda upgrade pyodbc

It's working now in both Linux and Windows.

Thanks, Max_

MaximoTrinidad commented 7 years ago

Aaahh! The excitement was short-lived.

As I was create my new VM environments in Azure, I try to replicate my steps building my Python Anaconda with no success for Linux.

I got Windows working but I'm still missing something for Linux and specially with Windows 10 Bash. I got on full Ubuntu OS working on my physical machine.

I'm trying to lay out the step to properly install Anaconda Python with PYODBC. I'm almost there!

:)

nehaljwani commented 7 years ago

@MaximoTrinidad Do share the exact error that you are facing while trying it on WSL.

MaximoTrinidad commented 7 years ago

@nehaljwani,

I was able to clear my Ubuntu OS in Azure by doing the following (and I'm still need to replicate again);

--Fix Anaconda 3.6.0 to 3.6.1 for Pyodbc: conda upgrade python conda install libgcc (--> seems like is needed) conda install pyodbc

Added path missing in ~/.bashrc

-- copy/paste from my working laptop Ubuntu OS laptop to my Ubuntu in Azure: export PATH=/sbin:$PATH export PATH="$PATH:/opt/mssql-tools/bin" export PATH=/opt/ssis/bin:$PATH export PATH="/home/maxt/anaconda3/bin:$PATH"

sudo apt update sudo apt upgrade

WSL is missing the ~/.bash_profile

--Add line export PATH="$PATH:/opt/mssql-tools/bin"

Now, on my WSL Bash session, I'm still having the an error message that may lead to missing packages:

Error

cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=orion;DATABASE=master;UID=sa;PWD=$SqlPwd01!') Traceback (most recent call last): File "", line 1, in pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (0) (SQLDriverConnect)"

Awesome! I cleared WSL too. Seems I was missing loading 'msodbcsql' package:

sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list exit sudo apt update sudo apt upgrade sudo ACCEPT_EULA=Y apt-get install msodbcsql

--Good (no error in connection string) maxt@Earth2:~$ python Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information.

import pyodbc cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=orion;DATABASE=master;UID=sa;PWD=$SqlPwd01!')

I'm still need to do another WSL rebuild on my Windows 10 Insider build in Azure. This way I will polish more my steps on how to setup Anaconda 4.3.1 with Python 3.6.1 and PYODBC.

:)

kenorb commented 7 years ago

Re:

Can't open lib '/usr/local/lib/libodbcinst.2.dylib' : file not found

Solution is to create odbcinst.ini and define path to your SQL ODBC driver.

Example solution on macOS:

printf "[ODBC Driver 13 for SQL Server]\nDescription=Microsoft ODBC Driver 13 for SQL Server\nDriver=/usr/local/lib/libmsodbcsql.13.dylib\n" >> ~/.odbcinst.ini

or:

cp -v "$(brew list msodbcsql | grep odbcinst.ini$)" ~/.odbcinst.ini

Follow-up: Microsoft/homebrew-mssql-release/issues/3 & Microsoft/homebrew-mssql-preview/issues/4

bigfoot88 commented 4 years ago

I encountered the same situation as you. When pyodbc accesses SQL Server on windows from Ubuntu 18.04, in addition to installing pyodbc, you also need to install SQL Server driver. After installation, you can access the database.

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15#ubuntu17

keitherskine commented 3 years ago

Closed due to inactivity. Feel free to re-open with current information if necessary.