brew: Error while importing sqlite: ImportError: No module named _sqlite3

  • Ran brew update and retried your prior step?
  • Ran brew doctor, fixed as many issues as possible and retried your prior step?
  • If you’re seeing permission errors tried running sudo chown -R $(whoami) $(brew --prefix)?

I basically tried everything. Whatever I found online regarding this issue and people were mentioning that it worked I did it… but it doesn’t work for me. For example brew rm python python3 sqlite --force and other things that I could remove I did it… but no luck…

I’m recently updated all of my Homebrew stuff when I upgraded to macOS 10.12… and here is the current situation… is there anything I can try before throwing away this Macbook Pro outside of my window?

$ brew install python sqlite
Warning: python-2.7.12 already installed
Warning: sqlite-3.14.2 already installed

#-----------------------------------------------------------------------------

$ which python
/usr/local/bin/python

#-----------------------------------------------------------------------------

$ find /usr/local -name sqlite
/usr/local/Cellar/sqlite
/usr/local/opt/sqlite

#-----------------------------------------------------------------------------

$ python
Python 2.7.12 (default, Sep 27 2016, 20:06:01)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import sqlite
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sqlite

>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
    from dbapi2 import *
  File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 33 (15 by maintainers)

Commits related to this issue

Most upvoted comments

That’s weird. Could you please try

sudo xcode-select --install

to install CLT and try again (brew update --force; brew uninstall --force python; brew install python)?

If that doesn’t work I’ll tell you a secret way.

Can I ask your opinion about brew cask

My personal opinion of cask is it’s pretty awful for any sort of management, but it’s useful for one off installations, and that’s what I use it for. Any cask lovers out there: I do not intend to spark an argument.

brew.sh

It’s fine, but

ln -s /usr/local/bin/gsha256sum /usr/local/bin/sha256sum

is pointless since the non-prefixed version is already in gnubin. Also, you should hard code $(brew --prefix coreutils)/libexec/gnubin (e.g. /usr/local/opt/coreutils/libexec/gnubin) to speed up shell init.

@zmwangx and now everything is nice and clean! 😃 Can I ask your opinion about brew cask… I used to have it like a million years ago… is it OK to use it?

Something is odd with my machine 😦 thanks man… I installed pyenv used all the versions from 2.7.8 - 2.7.12 and I downgraded the App Engine sdk as well… no luck… I’m ready!

giphy

$ pkgutil --lsbom com.apple.pkg.DevSDK_OSX1012 | cut -d / -f 2 | uniq
.
System
usr

As you can see, CLT package installs its contents into /System and /usr, both of which are overwritten by a major OS upgrade.

Magic! I really can’t believe that it worked 😃 Thank you very very nice…! Spent the whole evening on that… 😃

magic

So the good news is that my machine is very clean and nice…!!

the bad news is that I still have the same error: https://gist.github.com/lipis/946c17457cdd8acf45d6270091ebc63a

Segmentation fault: 11

If there are any clues above… fine… but in the meantime I’ll try to work on my older machine… and maybe downgrade (somehow) to El Capitan 😦

(Maybe also posting this somewhere else would make sense… I can’t be the only one…)

wzbcycv

and I’m also ready to run this beauty: brew.sh any other magic to add or remove?

(you can also totally ignore my questions…)

Opened https://github.com/Homebrew/homebrew-core/issues/5347 to see if we can prevent more users from wasting time on Python due to missing CLT.

Now you may try a binary installer from python.org directly but I doubt it would help much…

Huh sorry to hear that but no idea… I myself did run into the “Python quit unexpectedly” issue intermittently since 3.5 I believe (which is roughly the same time as 2.7.11), but it was pretty rare and never reproducible.

I’m sure I had them installed on that machine… as I think Homebrew requires that at one point… but after the Sierra upgrade things went sideways (as always)… thanks again! Cheers… 🍺 🍻 🍺

The secret way is

# Depending on current version of formula and OS
curl -LO https://homebrew.bintray.com/bottles/python-2.7.12.sierra.bottle.tar.gz
brew install ./python-2.7.12.sierra.bottle.tar.gz

But brew install python should really pour the bottle. Guess it’s because you’re missing CLT, but not sure, I’m not familiar with no-CLT configurations.

I still want to know the secret way though… in case of trouble in the future I can always come back here…

The beauty of Python! On it…

I just came back to my computer.

Used your bottles.

Info disagrees.

/usr/local/Cellar/python/2.7.12 (6,288 files, 85.3M) *
  Built from source on 2016-09-27 at 20:06:59

Judging from your desperateness, you should really consider pouring our bottle instead of trying to debug your source build.

But if you really want to debug your source build, show us your

brew config

and the conversation might be able to continue.

Awesome man! Much appreciated…

Maybe also change the first CLT to: Command Line Tools (CLT)

@reitermarkus Let’s see when the new one will overpass it…

And legacy-homebrew is 28. 😂

By the way…! Homebrew is on #43http://githubstats.lip.is

👍 Good luck with your clean install.

It’s just sucks… but that’s life 😃 When you play dangerous games…

Basically at the moment I’m backing up, committing my 3423 projects into GitHub making sure that 652TB of crap in Dropbox are synced and I’ll be ready to clean the shit out of it… I wanted to do that for quite some time now… so it looks like that day/night just arrived 😃

Or you can try installing just Python in a clean VM.

Unfortunately no, I’m not running into such issues on Sierra, and I doubt it’s our problem (most of my stuff run on Python 3 though, and almost always with a non system wide Python). Maybe you could give pyenv a try?

screen shot 2016-09-28 at 22 38 27 screen shot 2016-09-28 at 22 38 35

I might need to throw away this computer (or maybe just have clean install) after all… 😦

Not sure if that’s related but it looks like something is wrong again… that happens every time that I’m trying to deploy the app on App Engine… In case that matters… and yes I deleted every single trace of google-cloud-sdk and installed it again… no luck 😃

Maybe @zmwangx you have some other black magic that could help me…?

Glad to hear.

HOMEBREW_VERSION: 1.0.5-25-g7e93340
ORIGIN: https://github.com/Homebrew/brew.git
HEAD: 7e93340073106f9f5a4bef057823210fb432c064
Last commit: 8 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 81697c641696ca9249ff9c6b1a24095ccb0c04d8
Core tap last commit: 3 hours ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local/Homebrew
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: octa-core 64-bit haswell
Homebrew Ruby: 2.0.0-p648
Clang: 8.0 build 800
Git: 2.10.0 => /usr/local/bin/git
Perl: /usr/bin/perl
Python: /usr/local/bin/python => /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: 1.8.0_60
macOS: 10.12-x86_64
Xcode: 8.0
CLT: N/A
X11: 2.7.9 => /opt/X11

I don’t care about debugging… I just want to make it work… I thought by running brew install python would use your bottle 😃 Am I missing something?! How do I override… solve my problem?

Used your bottles. Here is the gist to avoid crappy comments.

Did you install python from source? Or did you pour our bottle? Please post of the output of the following commands:

brew info python
/bin/ls -l /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_sqlite3.so