質問

My specific question currently: where is pyodbc being installed by MacPorts? The overall question is: how does one install pyodbc on Mac OSX with MacPorts? Full story follows...

I'm using Mac OS X Lion (10.8.5) and Python 2.7 which is running from /Library/Frameworks/Python.framework/Versions/2.7/bin/python. I had FreeTDS already installed (wrote a bash script using fisql) but I also followed the instructions at http://www.cerebralmastication.com/2013/01/installing-debugging-odbc-on-mac-os-x/ and verified that UnixODBC is installed. Finally, I've run sudo port install py27-pyodbc successfully... and yet when I try import pyodbc, I get the error:

ImportError: No module named pyodbc

Sure enough, I do not see it when listing my available modules. I am fairly new to OSX, but I checked the symlinks in both /usr/bin and /usr/local/bin and they all point to the same place.

P.S. -- I'm still interested in the resolution of this for posterity, but I simply ran setup.py build and setup.py install from the pyodbc source and voila!... works.

役に立ちましたか?

解決

Here's what I've learned: MacPorts creates its own Python installation under /opt/local/Library/Frameworks/Python.framework which is confusingly similar to the system /Library/Frameworks/Python.framework. It calls the latter "python27-apple" (assuming version 2.7) and you can see all the Pythons it sees by running sudo port select --list python and you can make it use the system Python by running sudo port select python python27-apple. Now when you run sudo port install py27-pyodbc it should theoretically drop the library into the right folder (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc.so) ... but it does NOT. You can, however, copy the two files from /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyodbc* and it'll find them.

$ cp /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/* ./
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
>>> quit()

Note that this folder does not require elevated privileges as it is meant for drop-in 3rd party libraries. This is really not the best solution and I'm hoping someone else can tell me off and suggest a better one.

Reference: How to: Macports select python

他のヒント

You can add the path to PYTHONPATH so python knows it should look in that directory too.

export PYTHONPATH=$PYTHONPATH:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

After that the import should succeed.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top