Running Jupyter Notebook from cmd raises ModuleNotFoundError: No module named pysqlite2

前端 未结 5 1107
我寻月下人不归
我寻月下人不归 2020-12-06 19:59

The problem:

After reinstalling Anaconda I can no longer navigate to a folder using the command window where I\'ve got some .pynb files

相关标签:
5条回答
  • 2020-12-06 20:26

    Short answer:

    This appears to be a version issue as of 29.01.2019 only related to:

    Anaconda3-2018.12-Windows-x86_64:

    Jupyter Notebook 5.7.4
    Python 3.7.1 (default, Dec 10 2018, 22:54:23) 
    IPython 7.2.0
    

    Check the list in the details below to see versions that will not raise the ModuleNotFoundError: No module named pysqlite2 when launching Jupyter from batch, or even trying to install nbExtensions.

    For version Anaconda3-2018.12, Jupyter can be launched from batch using the setup from GokulDAS027 in this post, but it will not open automatically in your default web browser. You can also launch Jupyter from the Anaconda Navigator without problems.

    The details:


    Solution 1: Run more detailed batch


    It turns out that the suggestion from GokulDAS027 to the question Using a .bat to change directories and run Jupyter for some reason will open Jupyter without raising the sqlite error messages:

    C:\Users\**UserName**\Anaconda3\python.exe C:\Users\**UserName**\Anaconda3\cwp.py C:\Users\**UserName**\Anaconda3 C:\Users\**UserName**\Anaconda3\python.exe C:\Users\**UserName**\Anaconda3\Scripts\jupyter-notebook-script.py "**file location**"

    On my system, Jupyter will not automatically open the default web-browser though. Also, if you'd like to install Notebook Extensions, you'll get a related error message. Since I did not find this very satisfactory, I started some more digging on whether or not this is a problem for later versions of Anaconda as well:


    Solution 2: Install older versions of Anaconda


    I noticed some comments on github that pysqlite2 is not used in Python 3. I was pretty certain that I did not have the ModuleNotFoundError: No module named pysqlite2 about a year ago when I was already using Python 3, so I tested a few older Anaconda installations to check whether or not the same error would be raised.

    It appears that the pysqlite2 error will only be raised for the very latest version (per 29.01.2019):

    Anaconda3-2018.12

    Jupyter Notebook 5.7.4
    Python 3.7.1 (default, Dec 10 2018, 22:54:23) 
    IPython 7.2.0
    

    With the system setups described below (still on Windows 7, 64 bit) everything runs fine, meaning:

    1. Jupyter can be started from a command prompt (not only Anaconda prompt) by navigating to a folder and typing jupyter notebook, and it's launched automatically in the default web browser.

    2. nbExtensions can be installed using conda install -c conda-forge jupyter_contrib_nbextensions

    Tested versions from Anaconda Archive

    Anaconda3-5.3.1

    Jupyter Notebook 5.6.0
    Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)]
    IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
    

    Anaconda3-4.4.0

    Python 3.6.1 |Anaconda 4.4.0 (64-bit)|
    IPython 5.3.0
    

    Anaconda2-4.3.1-Windows-x86_64

    Jupyter Notebook 4.3.1
    Python 2.7.13 |Anaconda 4.3.1 (64-bit)| 
    IPython 5.1.0 
    
    0 讨论(0)
  • 2020-12-06 20:27

    This answer is for users who might have compiled Python from source and also for the users who dont have admin rights (as a result I cant use Homebrew). I faced the same error but my python environment is customised and I am not using anaconda or pyenv. A side note, my OS is macOS mojave 10.14.6.

    I recompiled and reconfigured sqlite manually from source package. Steps:

    1. Download sqlite tarfile from this page.
    2. Navigate to the /path/to/python_dir/Python-3.x.x/Modules where your Python version is installed. (Because I am not the admin I installed it here : /Users/myusername/python3. ) : /Users/myusername/python3/Python-3.6.8/Modules/
    3. Extract sqlite under /Modules/: tar zxf /Users/myusername/Downloads/sqlite.tar.gz
    4. cd sqlite
    5. configure sqlite locally : ./configure --prefix='/Users/myusername/python3'
      side note: without the prefix option make install will install files in default location. check this answer. So use the prefix option if your python is not at default location.
    6. make && make install
    7. go back to python folder and reconfigure python binaries, and point to sqlite :
      cd ../../ and then:
      ./configure --prefix='/Users/myusername/python3' --with-sqlite='/Users/myusername/python3'.
    8. make && make install

    Side note : It turns out that if you configured Python manually and you can't install some library using pip probably you have to configure and recompile that package from source. Download the tar file of your package and repeat the above steps for your package. I also had problems with zlib and openssl and i did the same as above.
    Some other threads you might find useful : this , maybe this also

    0 讨论(0)
  • 2020-12-06 20:30

    if you have oracle client installed for cx_Oracle package please check if you have /usr/lib in the DYLD_LIBRARY_PATH. Try removing /usr/bin from the path and see if it works.

    I had the same problem and this worked for me. I have tried it on MacOS.

    0 讨论(0)
  • 2020-12-06 20:39

    I was stuck on the same issue for like a day. finally found the solution its working now.

    The issue seems to arise from the missing of sqlite3.dll in path ".\Anaconda\Dlls\". I solved it by simply copying that .dll file from \Anaconda3\Library\bin and put it under the path mentioned above. This was life saviour.

    Thanks, Darsan

    0 讨论(0)
  • 2020-12-06 20:39
    1. from this link to download pysqlite: https://www.sqlite.org/download.html
    2. zip the file to the dir:(anaconda3\DLLs)
    0 讨论(0)
提交回复
热议问题