A jupyter notebook cannot import dirichlet_likelihood.py from lda2vec.
This py file exists in github for the current lda2vec.
I installed the module and opened the workbook, then attempted to run it. I suspect there is a very simple reason for my problem.
The notebook is
https://github.com/cemoody/lda2vec/blob/master/examples/twenty_newsgroups/lda2vec/lda2vec.ipynb
When I try the below at the python command-line (in the current environment) it does not give the below error and instead it wanted keras, which I installed. On the command line it says it cannot import preprocess.
uname -a
Linux ubuntu 4.18.0-15-generic #16~18.04.1-Ubuntu SMP Thu Feb 7 14:06:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
sudo apt-get install python3-venv
python3.6 -m venv .env
source .env/bin/activate
pip install --upgrade pip
pip install jupyter
pip install lda2vec
from lda2vec import preprocess, Corpus
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-2b87256bea6b> in <module>
----> 1 from lda2vec import preprocess, Corpus
2 import matplotlib.pyplot as plt
3 import numpy as np
4 get_ipython().run_line_magic('matplotlib', 'inline')
5
~/.env/lib/python3.6/site-packages/lda2vec/__init__.py in <module>
----> 1 import lda2vec.dirichlet_likelihood as dirichlet_likelihood
2 import lda2vec.embedding_mixture as embedding_mixture
3 from lda2vec.Lda2vec import Lda2vec as model
4 import lda2vec.word_embedding as word_embedding
5 import lda2vec.nlppipe as nlppipe
AttributeError: module 'lda2vec' has no attribute 'dirichlet_likelihood'
python
from lda2vec import preprocess, Corpus
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'preprocess'
EDIT
I got it work by doing these things
- Get ubuntu-18.04.2-desktop-amd64.iso
- Have BIOS virtualisation settings changed for hyper-V
- Make a VM in VMWare
- Increase memory to 3G
- Give it 40G of disk
Then in a terminal
sudo apt install python2.7
sudo apt install python-pip
pip install virtualenv
Mkdir 2.7env
Cd 2.7env
python2.7 -m venv .env
python2.7 -m virtualenv .env
source .env/bin/activate
pip install --upgrade pip
pip install jupyter
pip install -U spacy
python -m spacy download en
pip install wheel nltk gensim pyLDAvis lda2vec
sudo apt install git
git clone https://github.com/cemoody/lda2vec.git
cp ~/lda2vec/build/lib.linux-x86_64-2.7/lda2vec/corpus.py ~/2.7env/.env/lib/python2.7/site-packages/lda2vec/Corpus.py
cp ~/lda2vec/build/lib.linux-x86_64-2.7/lda2vec/preprocess.py ~/2.7env/.env/lib/python2.7/site-packages/lda2vec/preprocess.py
python -m pip install ipykernel
python -m ipykernel install --user
python lda2vec/examples/twenty_newsgroups/lda2vec/lda2vec_run.py
cd lda2vec/examples/twenty_newsgroups/lda2vec/
jupyter notebook
change the kernel to 2
In firefox open lda2vec.ipynb
As above, I am now stuck trying to get it to re-create the twenty_newsgroups npz file so I can eventually provide my own content. In case anyone out there understands this better, I suspect trying to run this script on VM with little RAM might be the problem but the error is reported as
(.env) craig#ubuntu:~/whcjimmy/lda2vec/examples/twenty_newsgroups/data$ python preprocess.py
Traceback (most recent call last):
File "preprocess.py", line 31, in <module>
n_threads=4)
File "/home/craig/whcjimmy/.env/lib/python3.6/site-packages/lda2vec-0.1-py3.6.egg/lda2vec/preprocess.py", line 104, in tokenize
vocab = {v: nlp.vocab[v].lower_ for v in uniques if v != skip}
File "/home/craig/whcjimmy/.env/lib/python3.6/site-packages/lda2vec-0.1-py3.6.egg/lda2vec/preprocess.py", line 104, in <dictcomp>
vocab = {v: nlp.vocab[v].lower_ for v in uniques if v != skip}
File "vocab.pyx", line 242, in spacy.vocab.Vocab.__getitem__
File "lexeme.pyx", line 44, in spacy.lexeme.Lexeme.__init__
File "vocab.pyx", line 157, in spacy.vocab.Vocab.get_by_orth
File "strings.pyx", line 138, in spacy.strings.StringStore.__getitem__
KeyError: "[E018] Can't retrieve string for hash '9243420536193520'. This usually refers to an issue with the `Vocab` or `StringStore`."
Alright I got this to work. The problems were
pick the right python to run a 4 year old git project. Python 2.7.
check the installed module has the code from the git repo
run through the problem in a python terminal
copy and edit python files go to 3
One problem above was to do with a changed API for a dependency.
ImportError: No module named 'spacy.en'
The original problem was likely due to something about git or python I am not familiar with. Still the git project self-tests all fail and its build fails.
But I have my jupyter notebook running and producing convincing outputs.
Related
I installed wxPython version 4.1.1 from pip3 and my python version is 3.8.9 on a M1 processor running MacOS Monterey.
Importing wx results in the following exception:
Traceback (most recent call last):
File "myPythonProgram.py", line 1, in <module>
import wx
File "/Library/Python/3.8/site-packages/wx/__init__.py", line 17, in <module>
from wx.core import *
File "/Library/Python/3.8/site-packages/wx/core.py", line 12, in <module>
from ._core import *
ImportError: dynamic module does not define module export function (PyInit__core)
I tried the following options but none of the following seemed to have worked and the result in the same exception, stated above:
Tried wxPython(4.1.1) installation using pip - python3 -m pip install -U --user wxPython==4.1.1
Tried wxPython(4.1.2) with pip3 install -U --user ./wxPython-4.1.2a1.dev5259+d3bdb143-cp38-cp38-macosx_11_0_universal2.whl
Tried compilation/installation of wxPython from source code
Any hints to resolve the issue?
I'm able to resolve the issue using by executing the following steps:
Install native minforge release from here
Create a virtual environment and install wxpython from mini-forge
conda create --name my_env_py38 python=3.8
conda activate my_env_py38
conda install -c conda-forge wxpython # installs wxPython version 4.1.1
I successfully installed Spacy using pip install spacy and alternatively through Pycharms virtual env, but when I import spacy in my program it's giving me the following error;
home/pi/.virtualenvs/cv/bin/python /home/pi/PycharmProjects/testSpeech/main.py
Traceback (most recent call last):
File "/home/pi/PycharmProjects/testSpeech/main.py", line 2, in <module>
import spacy
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/spacy/__init__.py", line 10, in <module>
from thinc.neural.util import prefer_gpu, require_gpu
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/thinc/neural/__init__.py", line 4, in <module>
from ._classes.model import Model # noqa: F401
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/thinc/neural/_classes/model.py", line 11, in <module>
from ..train import Trainer
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/thinc/neural/train.py", line 7, in <module>
from .optimizers import Adam, linear_decay
File "thinc/neural/optimizers.pyx", line 14, in init thinc.neural.optimizers
File "thinc/neural/ops.pyx", line 36, in init thinc.neural.ops
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/blis/__init__.py", line 3, in <module>
from .cy import init
ImportError: /home/pi/.virtualenvs/cv/lib/python3.7/site-packages/blis/cy.cpython-37m-arm-linux-gnueabihf.so: undefined symbol: __atomic_load_8
Process finished with exit code 1
Any idea what's happening?
You probably have a 32-bit OS? Instead, you will need a 64-bit OS with 64-bit python for spaCy v2, e.g.: https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2020-08-24/
As of spacy v2.3.5 you should be able to install spacy in a venv for linux aarch64 with:
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip setuptools
pip install spacy
Alternatively, there are binary linux aarch64 packages on conda-forge. There's a linux aarch64 miniforge installer and the install command would be conda install spacy. If you're not using the miniforge installer, then you need to add -c conda-forge or otherwise add the conda-forge channel.
See: https://github.com/explosion/spaCy/issues/6638
There was some problem while loading some library which was some prerequisite for spacy.
The problem was solved by calling the file via terminal with the following command;
LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libatomic.so.1.2.0 python3 main.py
I'm trying to create an LMDB data base file in Python to be used with Caffe according to this tutorial. The commands import numpy as np and import caffe run perfectly fine. However, when I try to run import lmdb and import deepdish as dd, I'm getting the following errors:
>>> import lmdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named lmdb
>>> import deepdish as dd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named deepdish
I'm running Python 2.7.9 through Anaconda 2.2.0 (64-bit) on Ubuntu 14.04. While installing the dependencies for Caffe according to this page, I've already installed the lmdb package through sudo apt-get install liblmdb-dev.
Any ideas why this error might be occuring?
Well, the apt-get install liblmdb-dev might work with bash (in the terminal) but apparently it doesn't work with Anaconda Python. I figured Anaconda Python might require it's own module for lmdb and I followed this link. The Python installation for lmdb module can be performed by running the command pip install lmdb in the terminal. And then import lmdb in Python works like a charm!
The above installation commands may require sudo.
If you're using Anaconda, then this can solve your problem (it worked for me):
conda install -c https://conda.binstar.org/dougal lmdb
For Anaconda users, installing python-lmdb package from conda-forge should fix the lmdb import error:
conda install -c conda-forge python-lmdb
This was tested on conda 4.5.11 on an lxc-containerized system running Ubuntu 18.04.
Note that there is a conda package named lmdb (without python-), installable via:
conda install -c conda-forge lmdb
that does not fix the import error.
Followed instructions on the github page. Of course, had to make minor changes since I was working with a windows 7 system. I got to the point post creating the virtual environment for portia to run. And I was trying to install the required packages using pip.
pip install -r requirements.txt
It failed with a log.
Now in the shell I try to run twistd, it gives error saying command not found. I even tried as follows:
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$ python ../../portia_env/Scripts/twistd.py -n slyd
Traceback (most recent call last):
File "../../portia_env/Scripts/twistd.py", line 13, in <module>
from twisted.scripts.twistd import run
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 53, in
<module>
_checkRequirements()
File "c:\Portia\portia_env\lib\site-packages\twisted\__init__.py", line 37, in
_checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zop
e.interface.
(portia_env)
deostroll#DEOTOP /c/Portia/portia/slyd (master)
$
Is there an alternate procedure to follow in order to make this work on windows?
It looks like zope.interface didn't install when you ran:
pip install -r requirements.txt
Could you try running the following and see if it works?
pip install zope.interface
I am trying to use pip on my Redhat system.
I installed pip following the instructions here, but when I try to use it, for example pip install, I get the following error code:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip
this issue due to common user do not have privilege to access packages py file.
1. root user can run 'pip list'
2. other common user cannot run 'pip list'
[~]$ pip list
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
solution :
root user login and run
chmod -R 755 /usr/lib/python2.7
fix this issue.
If pip is already installed and your unable to access it, one of the reason could be that you don't have permissions to read or execute the library. Try doing
sudo chmod -R u+rx /usr/lib/python2.7/site-packages/pip/
If pip is installed in a different folder, you can obtain the folder path by doing
>>> import pip
>>> pip.__path__
['/usr/lib/python2.7/site-packages/pip']
If you don't have root rights and running on python 2.6 then you can try this file https://bootstrap.pypa.io/2.6/get-pip.py (it is from same instruction you used, it is a simple python script which installs all dependencies and pip itself) and run it with command python get-pip.py --user