Unable to import Spacy in Python 3.7 - python

I have tried by installing spacy in new virtual environment as well just in case if there are any module version clashes but still gives the same error upon doing the spacy import
import spacy
Also tried with downgrading of the spacy version to 2.2.2.
Error Log:
Traceback (most recent call last):
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/catalogue.py", line 8, in <module>
import importlib.metadata as importlib_metadata
ModuleNotFoundError: No module named 'importlib.metadata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/testUser/Desktop/ml/test-project/src/EmailParser.py", line 3, in <module>
import spacy
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/spacy/__init__.py", line 10, in <module>
from thinc.neural.util import prefer_gpu, require_gpu
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/thinc/__init__.py", line 8, in <module>
from ._registry import registry
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/thinc/_registry.py", line 1, in <module>
import catalogue
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/catalogue.py", line 10, in <module>
import importlib_metadata
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 16, in <module>
from ._compat import (
File "/Users/testUser/.virtualenvs/mlv3/lib/python3.7/site-packages/importlib_metadata/_compat.py", line 115, in <module>
email.message_from_string
AttributeError: module 'email' has no attribute 'message_from_string'

Related

How to make jupyter-lab command global

I've added "C:\Users\sj\anaconda3\Scripts" to System environment variable list, but I got the following result.
C:\Users\sj>jupyter-lab
Traceback (most recent call last):
File "C:\Users\sj\anaconda3\lib\site-packages\jupyter_server\services\sessions\sessionmanager.py", line 8, in <module>
import sqlite3
File "C:\Users\sj\anaconda3\lib\sqlite3\__init__.py", line 57, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\sj\anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\sj\anaconda3\Scripts\jupyter-lab-script.py", line 5, in <module>
from jupyterlab.labapp import main
File "C:\Users\sj\anaconda3\lib\site-packages\jupyterlab\labapp.py", line 13, in <module>
from jupyter_server.serverapp import flags
File "C:\Users\sj\anaconda3\lib\site-packages\jupyter_server\serverapp.py", line 83, in <module>
from jupyter_server.services.sessions.sessionmanager import SessionManager
File "C:\Users\sj\anaconda3\lib\site-packages\jupyter_server\services\sessions\sessionmanager.py", line 11, in <module>
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
Could anyone help me to fix this and make "jupyter-lab" and "jupyter-notebook" global?

Numpy attempts to import the packages that it depends on from my project folder instead of the package install directory

I have python 3.8 and numpy 1.19.2 installed. Recently when I wrote in a blank REPL,
import numpy
I received this error:
Traceback (most recent call last):
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/compat/py3k.py", line 28, in <module>
import pickle5 as pickle
File "/home/rev/anaconda3/lib/python3.8/site-packages/pickle5/__init__.py", line 1, in <module>
from .pickle import *
File "/home/rev/anaconda3/lib/python3.8/site-packages/pickle5/pickle.py", line 33, in <module>
from struct import pack, unpack
ImportError: cannot import name 'pack' from 'struct' (/home/rev/Dokumenter/phd/tight/phd-2022/src/struct.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/core/__init__.py", line 70, in <module>
from . import numerictypes as nt
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/core/numerictypes.py", line 107, in <module>
from ._type_aliases import (
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/core/_type_aliases.py", line 27, in <module>
from numpy.compat import unicode
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/compat/__init__.py", line 12, in <module>
from . import py3k
File "/home/rev/anaconda3/lib/python3.8/site-packages/numpy/compat/py3k.py", line 30, in <module>
import pickle
File "/home/rev/anaconda3/lib/python3.8/pickle.py", line 33, in <module>
from struct import pack, unpack
ImportError: cannot import name 'pack' from 'struct' (/home/rev/Dokumenter/phd/tight/phd-2022/src/struct.py)
It seemed somehow it reacts to the file struct.py that is a recently created file somewhere in one of my Ph.D.-project-directories. After I renamed the file to struc.py, all was well.
How can I avoid this in the future? It's a problem if my documents starts crashing numpy.

2x ModuleNotFoundError Jupyter notebook

While attempting to run jupyter notebook in python3.6.3 on my gnome terminal I get the following output, running on UBUNTU:
Traceback (most recent call last):
File "/home/willem/.local/lib/python3.6/site-packages/notebook/services/sessions/sessionmanager.py", line 10, in <module>
import sqlite3
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/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/willem/.local/bin/jupyter-notebook", line 7, in <module>
from notebook.notebookapp import main
File "/home/willem/.local/lib/python3.6/site-packages/notebook/notebookapp.py", line 81, in <module>
from .services.sessions.sessionmanager import SessionManager
File "/home/willem/.local/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'
However, the module sqlite3 is present in my python3.6.3 directory. Which makes the problem rather vague.
Any suggestions for this problem to be fixed will be greatly appreciated

Error message: ImportError: No module named _caffe

I tried to install that install Caffe Tutorial, but I am block at this line in the tuto: ./tools/demo.py
I havre this error message:
MacBook-Pro-de-OlostA:fast-rcnn OlostA$ ./tools/demo.py
Traceback (most recent call last):
File "./tools/demo.py", line 19, in <module>
from fast_rcnn.config import cfg
File "/Users/OlostA/Technologies/fast-rcnn/tools/../lib/fast_rcnn/__init__.py", line 9, in <module>
from . import train
File "/Users/OlostA/Technologies/fast-rcnn/tools/../lib/fast_rcnn/train.py", line 10, in <module>
import caffe
File "/Users/OlostA/Technologies/fast-rcnn/tools/../caffe-fast-rcnn/python/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver
File "/Users/OlostA/Technologies/fast-rcnn/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py", line 13, in <module>
from ._caffe import Net, SGDSolver
ImportError: No module named _caffe
Thanks in advance.

Why does python35 import try to load python27 package?

I have python2.7 and python3.5 installed via Macports. I am trying to get neovim up and running and for this I ran
$ sudo pip2 install neovim
$ sudo pip-3.5 install neovim
Which installs the packages into different subdirs of /opt/local/Library/Frameworks/Python.framework/Versions/. Now when running Python 3.5, import neovim tries to load the 2.7 package (which fails), as I can see from the stack trace.
The full error is this:
$ python3.5 -c "import neovim"
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/__init__.py", line 7, in <module>
from .uv import UvEventLoop
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/uv.py", line 5, in <module>
import pyuv
ImportError: No module named 'pyuv'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/asyncio.py", line 19, in <module>
import asyncio
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/__init__.py", line 21, in <module>
from .base_events import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/base_events.py", line 18, in <module>
import concurrent.futures
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/_base.py", line 357
raise type(self._exception), self._exception, self._traceback
^
SyntaxError: invalid syntax
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/__init__.py", line 11, in <module>
from .msgpack_rpc import (ErrorResponse, child_session, socket_session,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/__init__.py", line 8, in <module>
from .event_loop import EventLoop
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/__init__.py", line 12, in <module>
from .asyncio import AsyncioEventLoop
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/neovim/msgpack_rpc/event_loop/asyncio.py", line 22, in <module>
import trollius as asyncio
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/__init__.py", line 21, in <module>
from .base_events import *
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/base_events.py", line 39, in <module>
from . import coroutines
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/coroutines.py", line 16, in <module>
from . import futures
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/futures.py", line 19, in <module>
from . import executor
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/trollius/executor.py", line 12, in <module>
import concurrent.futures
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/concurrent/futures/_base.py", line 357
raise type(self._exception), self._exception, self._traceback
^
SyntaxError: invalid syntax
What do I have to do in order for Python 2.7 and 3 to coexist peacefully on my system?
I recently had this problem as well, but it was not related to PYTHONPATH, which on my machine was unset. In my situation Python and pip were installed via MacPorts. Cleaning, self-updating MacPorts and then updating pip to the most recent version, and then running the following resolved the issue:
port select --set pip pip35

Categories