I recently upgraded my OS to High Sierra, and since then I have not been able to use the sqlanydb library with my flask app. I was using SQLAnywhere16 and recently upgraded to SQLAnywhere17 after reading that it might solve problem, but it did not.

I start by sourcing sa_config.sh located at /Applications/SQLAnywhere17/System/bin64/sa_config.sh. Then I run my flask app. In the initialization of my app, I create a connection using sqlanydb.connect(), and I am met with the following traceback.

File "/usr/local/lib/python3.6/site-packages/lib/python/site-packages/sqlanydb.py", line 522, in connect return Connection(args, kwargs) File "/usr/local/lib/python3.6/site-packages/lib/python/site-packages/sqlanydb.py", line 538, in __init__ parent = Connection.cls_parent = Root("PYTHON") File "/usr/local/lib/python3.6/site-packages/lib/python/site-packages/sqlanydb.py", line 464, in __init__ 'libdbcapi_r.dylib') File "/usr/local/lib/python3.6/site-packages/lib/python/site-packages/sqlanydb.py", line 456, in load_library raise InterfaceError("Could not load dbcapi. Tried: " + ','.join(map(str, names))) sqlanydb.InterfaceError: (u'Could not load dbcapi. Tried: None,dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib', 0)

When I run the python3.6 interpreter, I am able to import the sqlanydb and connect to my database just fine, with no error. But when I try to connect inside my flask app, I get this error.

asked 21 Feb, 18:29

midnight_milloir's gravatar image

accept rate: 100%


When I open a python interpreter, or just run a plain python script, I added these lines to make sure that sourcing sa_config.sh was definitely adding the paths to my environment.

print(os.environ['PATH']) print(os.environ['NODE_PATH']) print(os.environ['DYLD_LIBRARY_PATH'])

Running those lines in the python interpreter or in a plain python script, it prints out the correct paths. However, when I added those three lines to just above the line where my flask app was breaking, it prints out the correct paths for the first two, but a key error is raised on $DYLD_LIBRARY_PATH. Apparently flask is unable to see the library path added by sa_config.sh. When I run


in a terminal, it prints the path just fine. So then is flask not using the right environment? Why is flask unable to see the updated library path?

(22 Feb, 14:15) midnight_mil...

I'm posting this as a solution because it at least solves my current problem. However, I think this is worth looking into more, and I'll be taking this problem to the Flask contributors.

It seems that when I run flask the following way, I get all of the errors that I have mentioned.

export FLASK_APP=modules export FLASK_DEBUG=1 flask run

This seems to wipe out the added key: $DYLD_LIBRARY_PATH. However, when starting flask the following way, by calling app.run(), the key is not wiped out and sqlanydb is able to correctly locate the library files.

from myapp import app

if __name__== '__main__': app.run(debug=True)

If anyone on this forum has an explanation for what I'm seeing, I'm all ears. This is all very confusing. Again, everything worked just fine until I upgraded to High Sierra, so I suspect that must have some part to play.

permanent link

answered 22 Feb, 14:48

midnight_milloir's gravatar image

accept rate: 100%

edited 22 Feb, 14:49

High Sierra will "purge" DYLD_LIBRARY_PATH now for protected processes - see the docs from Apple.

permanent link

answered 23 Feb, 08:52

Jeff%20Albion's gravatar image

Jeff Albion
accept rate: 24%

edited 23 Feb, 10:51

Graeme%20Perrow's gravatar image

Graeme Perrow

Ah, I see. Thank you for pointing me in the right direction.

(23 Feb, 16:06) midnight_mil...
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 21 Feb, 18:29

question was seen: 377 times

last updated: 23 Feb, 16:06