4

I am trying to host my app on IBM bluemix. In my app, I have used flask and I am trying to Connect to Azure SQL Server database. So for that, I am using Pyodbc.

So in requirement.txt file I have given pip install pyodbc and pip install flask. These things are getting installed on my local machine and the app is running fine. I am getting the result from the database .

But when I am trying to deploy my application on IBM bluemix, while pushing the files on the server it is giving me an error. I have attached the error screenshot below.

The content of requirement.txt is here

unixodbc-dev
pyodbc==3.1.1
Flask==0.12.2

Error Message

PriyalChaudhari
  • 363
  • 1
  • 7
  • 23
  • The environment is linux that is defined by a cloud foundry buildpack: http://docs.cloudfoundry.org/buildpacks/python/. You don't have access to install package inside the environment such as unixODBC. I'm looking to see if there is an alternative buildpack that contains unixODBC. – Chris Snow Jul 07 '17 at 08:38
  • @ChrisSnow these are the contents of my requirement.txt `unixodbc-dev pyodbc==3.1.1 Flask==0.12.2` – PriyalChaudhari Jul 07 '17 at 17:17
  • I've created a more specific question here: https://stackoverflow.com/questions/44982510/fatal-error-sql-h-with-unixodbc-and-pyodbc-as-a-vendor-app-dependency – Chris Snow Jul 08 '17 at 04:32
  • @ChrisSnow thank you i will keep track of it – PriyalChaudhari Jul 08 '17 at 05:34
  • @ChrisSnow thank you i will keep track of it – PriyalChaudhari Jul 08 '17 at 05:35

2 Answers2

1

One solution is to use miniconda to install your dependencies instead of pip. Using miniconda with the buildpack is documented here.

See here for more information on using miniconda to install pyodbc.

Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • Thank you. I have tried that solution . my app is getting deployed on server now and I am getting no error. While running that app on bluemix server i am getting this error `pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")` I am posting my code in aap.py file in next comment – PriyalChaudhari Jul 11 '17 at 01:31
  • This is my code for which i am getting this error. This code is working on my local machine. but giving above error on bluemix. `@app.route('/sql//') def api_sql(lat,long): cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=prashantvikramsingh.database.windows.net;DATABASE=Zillow;UID=prashant;PWD=Pvs758993@') cursor = cnxn.cursor() cursor.execute("SELECT top 10 * FROM [dbo].[distance] ("+lat+","+long+") order by distance") rows = cursor.fetchall()` – PriyalChaudhari Jul 11 '17 at 01:32
  • Have a look at this question and answer: https://stackoverflow.com/questions/38534154/linux-python3-cant-open-lib-sql-server. If that doesn't solve your problem, I suggest you accept this answer to your original question and then create a new question. – Chris Snow Jul 11 '17 at 03:32
-1

The error message error: command 'gcc' failed with exit status 1 makes it seem like perhaps you need to install the gcc C/C++ compiler on that machine.

The pyodbc docs say:

Windows

On Windows, you will need the appropriate Microsoft Visual C++ compiler. To build Python 2.4 or 2.5 versions, you will need the Visual Studio 2003 .NET compiler. Unfortunately there is no free version of this.

For Python 2.6 and above, you can use the free Visual C++ 2008 Express compiler. (Do not use the 2010 version! You need to use the version that your Python distribution was built with.)

You can create a Windows installer using: python setup.py bdist_wininst

Other

To build on other operating systems, use the gcc compiler.

On Linux, pyodbc is typically built using the unixODBC headers, so you will need unixODBC and its headers installed. On a RedHat/CentOS/Fedora box, this means you would need to install unixODBC-devel:

yum install unixODBC-devel


Related: Unable to install pyodbc on Linux

Nathan Wailes
  • 9,872
  • 7
  • 57
  • 95
  • how do i install these things? Do i have to write them in requirement.txt I tried putting unixODBC-devel and gcc-c++. – PriyalChaudhari Jul 07 '17 at 06:14
  • You install it from the command line. If your OS is Ubuntu, [this answer](https://stackoverflow.com/a/9087394/4115031) suggests running `sudo apt-get install unixodbc-dev`. – Nathan Wailes Jul 07 '17 at 06:18
  • i am using windows and not getting the command for windows. tried installing it using pip but it says package not found – PriyalChaudhari Jul 07 '17 at 06:20
  • pyodbc is installed on my local machine and running fine. When i try to host the app on IBM bluemix it is giving that error – PriyalChaudhari Jul 07 '17 at 06:27
  • Are you sure your Bluemix server is running Windows? It looks from your error like your server is running Linux. – Nathan Wailes Jul 07 '17 at 06:34