7
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

Organization

pyenv, pipenv 環境でjupyter notebook使う時にsqliteに関するエラーが出たとき

環境

  • ubuntu 18.04
  • pyenv 1.2.9-2-g6309aaf2
  • pipenv, version 2018.11.26

jupyter 関連

  • jupyter 1.0.0
  • jupyter-core 4.4.0
  • ipywidgets 7.4.2

エラー

pipenvでpython 3.6.8を使ってjupyter notebookを起動しようと
しているところ。

(someenv)$ jupyter notebook
Traceback (most recent call last):
  File "/home/hoge/.local/share/virtualenvs/someenv-EUFWfC8N/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 10, in <module>
    import sqlite3
  File "/home/hoge/.pyenv/versions/3.6.8/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/home/hoge/.pyenv/versions/3.6.8/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/hoge/.local/share/virtualenvs/someenv-EUFWfC8N/bin/jupyter-notebook", line 6, in <module>
    from notebook.notebookapp import main
  File "/home/hoge/.local/share/virtualenvs/someenv-EUFWfC8N/lib/python3.6/site-packages/notebook/notebookapp.py", line 86, in <module>
    from .services.sessions.sessionmanager import SessionManager
  File "/home/hoge/.local/share/virtualenvs/someenv-EUFWfC8N/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 13, in <module>
    from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'

解決策

原因はsqliteが入っていなかったからなのだが、pythonのインタプリタも再インストしないといけないのが注意点。

1.sqlite入れる

ここを参考にしてsqliteとその依存を入れる。

$ sudo apt install libsqlite3-dev libreadline6-dev libbz2-dev libssl-dev libsqlite3-dev libncursesw5-dev libffi-dev libdb-dev libexpat1-dev zlib1g-dev liblzma-dev libgdbm-dev libmpdec-dev

2.pythonインタプリタ一旦消す

pythonインタプリタのsetup時にsqlite関連のパッケージがあると、使えるようにしてくれるみたいなので、pyenvで使おうとしているpythonインタプリタを一旦消していれ直す。

$ pyenv versions
* system (set by /home/hoge/.pyenv/version)
  3.6.8
  3.7.2
$ pyenv uninstall 3.6.8
pyenv: remove /home/hoge/.pyenv/versions/3.6.8? y
$ pyenv versions
* system (set by /home/hoge/.pyenv/version)
  3.7.2

3.入れ直す

入れ直す。(Pipfileが書いてあるとする。)

$ pipenv install
Warning: Python 3.6.8 was not found on your system...
Would you like us to install CPython 3.6.8 with pyenv? [Y/n]: Y]\
Error: invalid input
Would you like us to install CPython 3.6.8 with pyenv? [Y/n]: Y
Installing CPython 3.6.8 with pyenv (this may take a few minutes)...
✔ Success! 

うごいた。

$ pipenv shell
Launching subshell in virtual environment...
$ jupyter notebook
[I 15:23:07.943 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
[I 15:23:08.055 NotebookApp] Serving notebooks from local directory: /home/hoge/Works/someenv

おわりに

ぶっちゃけpipenv と pyenvはこのエラーにあんま関係ない。この辺の使って真っさらな環境に新しくjupyter notebook入れようとすると起きやすいとおもう。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
7
Help us understand the problem. What are the problem?