3

I'm on Mac OSX and I cannot import sqlalchemy.

Here is what I did. I ran:

$ pip install sqlalchemy
Requirement already satisfied: sqlalchemy in /usr/local/lib/python2.7/site-packages (1.3.1)

I verified that sqlalchemy was installed by running:

$ ls /usr/local/lib/python2.7/site-packages | grep sqlalchemy
flask_sqlalchemy
sqlalchemy

I opened my python interpreter and ran:

$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sqlalchemy
>>>

So I thought this might be a case where my system has two python interpreters and only one can see the package. I ran a which command like so...

$ which -a python
/usr/bin/python

So I only have one python interpreter installed, sqlalchemy is installed, but I cannot import it? Any tips?

b10hazard
  • 7,399
  • 11
  • 40
  • 53
  • 1
    Try `from flask_sqlalchemy import SQLAlchemy` (https://flask-sqlalchemy.palletsprojects.com/en/2.x/quickstart/#a-minimal-application) – rst-2cv Oct 09 '19 at 12:37
  • 1
    Check your python path, just to be sure. `import sys` and `print(sys.path)`. Have you used brew at some point? What does `which pip` say? This seems highly relevant: https://stackoverflow.com/questions/37341614/modules-are-installed-using-pip-on-osx-but-not-found-when-importing – Ilja Everilä Oct 09 '19 at 14:19
  • @IljaEverila You're right! /usr/local/lib/python2.7/site-packages wasn't in my python path. Grrrrrr. Such a simple fix. I don't know how that happened. If you post it as an answer I will accept it. Thanks! – b10hazard Oct 09 '19 at 15:24
  • 1
    I think all I'd be able to write down as an answer has already been written in these prior Q/A, so I think your question serves best as a signpost to them. Did you btw check if your `pip` is in fact in `/usr/local/bin`? One answer in the linked Q/A suggested trying `python -mpip install sqlalchemy` and see if it's then installed to the correct python installations site packages. – Ilja Everilä Oct 09 '19 at 15:54

0 Answers0