Could not run jupyter on Mac OS (gives pysqlite2 errror) - python

I have installed anaconda in mac os sierra. Simple python scripts run fine. However, when I try to run jupyter-notebook it fails.
The error message is following:
Traceback (most recent call last):
File "/Users/poudel/anaconda3/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 10, in <module>
import sqlite3
File "/Users/poudel/anaconda3/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/Users/poudel/anaconda3/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: dlopen(/Users/poudel/anaconda3/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-darwin.so, 2): Symbol not found: _sqlite3_enable_load_extension
Referenced from: /Users/poudel/anaconda3/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-darwin.so
Expected in: /usr/lib/libsqlite3.dylib
in /Users/poudel/anaconda3/lib/python3.6/lib-dynload/_sqlite3.cpython-36m-darwin.so
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/poudel/anaconda3/bin/jupyter-notebook", line 7, in <module>
from notebook.notebookapp import main
File "/Users/poudel/anaconda3/lib/python3.6/site-packages/notebook/notebookapp.py", line 79, in <module>
from .services.sessions.sessionmanager import SessionManager
File "/Users/poudel/anaconda3/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'
I checked the dylib file, but it is there. What's wrong here?
Bhishan:ls /usr/lib/libsqlite3.dylib
/usr/lib/libsqlite3.dylib*
Similar problems:
No module named _sqlite3
But they did not solve my problem.

Your problem is most likely due to several python envirionments.
Check this question.
Also this question maybe relevant.
Also try to see all installed packages with conda.

I have faced the same issue.
For me installing sqlite via brew solved the issue.
brew install sqlite

Related

Error in running python file using ASE library

I am trying to run a python script using ASE library, I have installed ase (https://wiki.fysik.dtu.dk/ase/install.html)and run my python script using this library on my terminal. I have made a virtual env named 'MLC_env' and have already installed the ase library there.
There is a folder 'Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase' which got installed over there. Now the the website (https://pypi.org/project/ase/) says Add ~/ase to your $PYTHONPATH environment variable and add ~/ase/bin to $PATH (assuming ~/ase is where your ASE folder is).
I am not able to figure out what exactly I have to do? How to add this ase folder to my pythonpath? Any suggestions will be helpful.
I tried to follow this answer Permanently add a directory to PYTHONPATH? , according to this I can try doing export PYTHONPATH="${PYTHONPATH}:/my/other/path"" where ~/ase will be the full path name of the ase folder. Shall I go ahead with this? any suggestions.
Python script
from ase import Atoms
atoms = Atoms('N2')
print(atoms.positions)
Error: While trying to run the above python script
(MLC_env) (base) anshumansinha#Anshumans-MacBook-Pro-3 Q1 % python3 struct.py
Traceback (most recent call last):
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/py3k.py", line 24, in <module>
import pickle5 as pickle
File "/Users/anshumansinha/.local/lib/python3.10/site-packages/pickle5/__init__.py", line 1, in <module>
from .pickle import *
File "/Users/anshumansinha/.local/lib/python3.10/site-packages/pickle5/pickle.py", line 33, in <module>
from struct import pack, unpack
File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
from ase import Atoms
ImportError: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/overrides.py", line 8, in <module>
from numpy.compat._inspect import getargspec
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/__init__.py", line 12, in <module>
from . import py3k
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/compat/py3k.py", line 26, in <module>
import pickle
File "/Users/anshumansinha/miniforge3/lib/python3.10/pickle.py", line 33, in <module>
from struct import pack, unpack
File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
from ase import Atoms
ImportError: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/anshumansinha/Desktop/MLC/HW1/Q1/struct.py", line 1, in <module>
from ase import Atoms
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py", line 17, in <module>
from ase.atom import Atom
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/atom.py", line 3, in <module>
import numpy as np
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/__init__.py", line 141, in <module>
from . import core
File "/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/Users/anshumansinha/Desktop/MLC/MLC_env/bin/python3"
* The NumPy version is: "1.24.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: cannot import name 'Atoms' from partially initialized module 'ase' (most likely due to a circular import) (/Users/anshumansinha/Desktop/MLC/MLC_env/lib/python3.10/site-packages/ase/__init__.py)

ModuleNotFoundError: No module named '_sqlite3' Error when try to import sqlite3 and Django in Ubuntu

I tried to Create Django Project. I'm able to create project but not able to run the runserver command. I got below error. I also tried to import sqlite3 got same error
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/sqlite3/__init__.py", line 57, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.11/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
>>>
Python version: Python 3.11.0
As Chris suspected the Python 3.11 is causing the issues I don't know why but I just downgraded to 3.8.10 and it resolved the issue.

"ImportError: No module named six" ubuntu 20.04

when running "src/bitmessagemain.py" in the terminal it shows
Traceback (most recent call last):
File "src/bitmessagemain.py", line 33, in <module>
import shared
File "/home/otsudo/Desktop/PyBitmessage-0.6/src/shared.py", line 19, in <module>
import highlevelcrypto
File "/home/otsudo/Desktop/PyBitmessage-0.6/src/highlevelcrypto.py", line 16, in <module>
from bmconfigparser import BMConfigParser
File "/home/otsudo/Desktop/PyBitmessage-0.6/src/bmconfigparser.py", line 10, in <module>
from six import string_types
ImportError: No module named six
I am guessing it has to do something with the virtualenv due to bitmessage still running on python 2.7 but I cant figure it out. I've made the environment for bitmessage to run in and I keep getting the error.
You probably don't have the six Python module installed,
try this:
pip install six

Problem launching Jupyter Notebook from Anaconda

I am having issues launching Jupyter Notebook. I have tried to do it two ways and seem to get errors.
1 - Launching from the Anaconda Prompt using the command jupyter notebook or directly choosing from the Anaconda menu
I get the following:
(base) C:\Users\metni>jupyter notebook
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\lib\site-packages\jsonschema\__init__.py", line 31, in <module>
from importlib import metadata
ImportError: cannot import name 'metadata' from 'importlib' (C:\Users\metni\anaconda3\lib\importlib\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\validator.py", line 12, in <module>
from jsonschema import ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\jsonschema\__init__.py", line 33, in <module>
import importlib_metadata as metadata
ModuleNotFoundError: No module named 'importlib_metadata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\notebookapp.py", line 80, in <module>
from .services.contents.manager import ContentsManager
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\services\contents\manager.py", line 17, in <module>
from nbformat import sign, validate as validate_nb, ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\__init__.py", line 32, in <module>
from .validator import validate, ValidationError
File "C:\Users\metni\anaconda3\lib\site-packages\nbformat\validator.py", line 23, in <module>
raise ImportError(str(e) + verbose_msg)
ImportError: No module named 'importlib_metadata'
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
2 - Launching from the command line with the same command
I get the following:
C:\Users\metni>jupyter notebook
Traceback (most recent call last):
File "C:\Users\metni\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in <module>
from notebook.notebookapp import main
File "C:\Users\metni\anaconda3\lib\site-packages\notebook\notebookapp.py", line 64, in <module>
from tornado import httpserver
File "C:\Users\metni\anaconda3\lib\site-packages\tornado\httpserver.py", line 29, in <module>
import ssl
File "C:\Users\metni\anaconda3\lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
It seems like this is referring to a package called jsonschema which is not installed apparently, but running a pip install jsonschema does not solve the problem for me...
In the answer above I also have two two commands but they are a bit different
source /opt/anaconda/bin/activate root
and then
jupyter notebook
It seems like you have to go into your anaconda directory then bin, then you can
"activate root"
It also looks like you need to install some other dependencies for jupyter to run. Where is says
Jupyter notebook format depends on the jsonschema package:
https://pypi.python.org/pypi/jsonschema
Please install it first.
So if the above doesn't work try installing the other dependency and try again
Based on this answer from a similar question, I managed to solve the problem by running these two commands:
conda update -n root conda
conda update --all
I thus updated all packages, and the notebook is now launching.

ImportError: No module named _io

When I compile my python scripts I'm getting the following error message. This started happening when I installed Anaconda. I've tried to find a solution online to the problem but I've had no luck. Can anyone help with solving this?
Traceback (most recent call last):
File "query.py", line 1, in <module>
import mysql.connector
File "/usr/local/lib/python2.7/dist-packages/mysql/connector/__init__.py", line 37, in <module>
from .connection import MySQLConnection
File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection.py", line 27, in <module>
from io import IOBase
File "/usr/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: No module named _io
Are you using virtualenv? When I ran into this issue it was because of some server update which messed with the python version being used by my virtualenv. I solved the problem by deleting the virtualenv and making a new identical one.

Categories