Module import issue with a Japanese Tokenizer - python

I am trying to get the JapaneseTokenizer working in python, but I am having trouble with one of the modules it depends on. Here is the trace of the errors I am getting:
/Users/home/PycharmProjects/SubLingo/application/tokenizerTest.py
Traceback (most recent call last):
File "/Users/home/PycharmProjects/SubLingo/application/tokenizerTest.py", line 1, in <module>
import JapaneseTokenizer
File "/Users/home/PycharmProjects/SubLingo/venv/lib/python3.7/site-packages/JapaneseTokenizer/__init__.py", line 6, in <module>
from JapaneseTokenizer.jumanpp_wrapper import JumanppWrapper
File "/Users/home/PycharmProjects/SubLingo/venv/lib/python3.7/site-packages/JapaneseTokenizer/jumanpp_wrapper/__init__.py", line 1, in <module>
from .jumanpp_wrapper import JumanppWrapper
File "/Users/home/PycharmProjects/SubLingo/venv/lib/python3.7/site-packages/JapaneseTokenizer/jumanpp_wrapper/jumanpp_wrapper.py", line 2, in <module>
from pyknp import Jumanpp
ImportError: cannot import name 'Jumanpp' from 'pyknp' (/Users/home/PycharmProjects/SubLingo/venv/lib/python3.7/site-packages/pyknp/__init__.py)
As you can see Jumanpp_wrapper is trying to import the module Jumanpp from pyknp. I have looked into the pyknp package currently installed on my machine and it does not have a module with this name. This leads me to conclude that the version of pyknp I have installed is not compatible with Jumanpp, so there must be another version available somewhere. The trouble is I install pyknp using the pip installer on my Mac, as recommended on the pyknp official site, so it should be the most current version. I'm not sure how to get an alternative version that contains the necessary module. I hope someone can point me in the right direction.

I'm a developer of the package. I kindly thank you for using my package.
I fixed bugs related to the issues here and released newer package version 1.4.
https://github.com/Kensuke-Mitsuzawa/JapaneseTokenizers/releases/tag/1.4
You could install/upgrade the package with pip also.
Install pip install JapaneseTokenizer / Upgrade pip install -U JapaneseTokenizer

I have been in direct contact with the developer of JapaneseTokenizer who has kindly given permission for me to repost his answer to my query:
I'm glad that you sent me a message about the issue. I read your post at StackOverflow. As other user suggested, the main issue is that pyknp package does not have juman++ module. I don't know the reason, but an author of pyknp package removed module for juman++.
The straightforward way to solve this issue is that you install pyknp package version 3 from here and install it your environment.
The main procedure is below.
remove pyknp package from your environment pip uninstall pyknp
get download pyknp package previous version. http://nlp.ist.i.kyoto-u.ac.jp/DLcounter/lime.cgi?down=http://lotus.kuee.kyoto-u.ac.jp/nl-resource/pyknp/pyknp-0.3.tar.gz&name=pyknp-0.3.tar.gz
install the pyknp=0.3 with pip install pyknp-0.3.tar.gz
From now, I revise JapaneseTokenizer package. It might take some weeks. Next time you try to install JapaneseTokenizer package, everything will be fine.
Again, thanks for giving me a message.
Best,
Kensuke Mitsuzawa

Related

ModuleNotFoundError: No module named 'cryptography'

these are the Error messages I am geeting on running any of my project modules.
Traceback (most recent call last):
File "C:\Users\hsnl\BlockchainCodesTutor\Wallet.py", line 3, in <module>
import Transactions
File "C:\Users\hsnl\BlockchainCodesTutor\Transactions.py", line 2, in <module>
import Signatures
File "C:\Users\hsnl\BlockchainCodesTutor\Signatures.py", line 2, in <module>
import cryptography
ModuleNotFoundError: No module named 'cryptography'
I have already installed the cryptography module and was working perfectly until today I start getting this message that " No module named 'cryptography'".
I have again installed the cryptography as well as pip package but still showing the same error.
There might be loose versions running on your system. Please try the following:
python -m pip uninstall cryptography
python -m pip install cryptography
You can also check out this with python -m to make sure you are not using a loose pip.
You might not have cryptogtaphy installed correctly. I see you are using windows. Open commandline as an administrator and run pip install cryptography again. Enshure that the installation finishes without any errors and consider to restart your python interpreter after installation.
For further help you should post more details like the output of pip and your code leading to the error, so a more detailed answer for your problem can be given.
Try download cryptography whl from here.
Then use pip install cryptography-XXX.whl
For example:
pip install cryptography-3.3.1-cp36-abi3-win_amd64.whl
And now just supports python2.7 and python3.6.

ModuleNotFoundError: No module named 'pynput' Python3 and pip3

I want to use 'pynput', so I used pip to add it to my environment.
The installation proceeds without problem.
But I am unable to import it into my project.
I am using python 3.8.1 on my environment.
I used pip3 for installation.
I have already tried to install pynput, uninstall it and reinstall it multiple times.
My .py file doesn't have a confusing name like "pynput.py"
I am comfortable with my environment when I try to execute my file.
I am trying to run from my terminal or VSCodium, and neither of them works.
And I work on Debian 10.
pip freeze :
pynput==1.6.7
python-xlib==0.26
six==1.14.0
Traceback :
Traceback (most recent call last):
File "./play.py", line 6, in <module>
from pynput import keyboard
ModuleNotFoundError: No module named 'pynput'
So I don't understand why it doesn't work.
thank you in advance for your help :)
When creating my project, I was not working under an environment, so I used the classic shebang: #!/bin/python3.
Then, I went under an environment to use pynput, but I just forgot to change my shebang to #!/usr/bin/env python.
So, actually, I didn't risk finding pynput
It might be possible you have two versions. Rry installing with python3 -m pip install pynput or you should use some older version of Python. I am using 3.7.5 and its works perfect for me.
Try importing from the terminal.

OpenCV in Python: "ImportError: DLL load failed"

So many questions already about this topic, but I didn't find any satisfying answer about the "DLL not found" traditional issue.
I'm using Python 3.5 installed via Anaconda 3;
I have installed with pip the 'official' opencv_python-3.2.0.6-cp34-cp34m-win_amd64.whl (right from here https://pypi.python.org/pypi/opencv-python);
Windows version is 7 - 64 bits;
I have uninstalled all the redistributable VC++ that were present on my machine and reinstalled its 2015 version - so the famous as well as mandatory DLL msvcp140.dll is present on my laptop;
the cv2 module is present in the Lib/site-packages directory;
it contains, among others, file 'cv2.cp35-win_amd64.pyd'.
Meanwhile, I still can't get access to cv2:
>>> import cv2
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import cv2
File "C:\Program Files\Anaconda3\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: The specified module could not be found.
Modifying the name of the .pyd --> cv2.pyd does not solve the problem, nor does the installing via pip of the unofficial but great wheel version from Gohlke (http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv)
Any idea about what is going on?
As mentioned in the comment which I didn't notice at first, you can resolve this by installing from the unofficial site (Gohlke)
(http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv)
I uninstalled the official one by calling:
pip uninstall opencv-python
And then downloaded the .whl package from the mentioned site (you need to carefully choose the correct python version and the correct processor architecture x86 or x64).
And then, go to the path where the .whl file is downloaded and call:
pip install opencv_python-x.x.x-cpxx-cpxxm-win_xx.whl
Regarding the comment in the question, always remove any existing opencv package before installing another one because, opencv from unofficial and official sites will be considered as 2 packages by pip.
You can install official opencv if you follow my answer here. You get that error because of a problem with Anaconda.
But if you install official opencv it will autocomplete and give suggestions in your python IDE (see this). So, if you need autocomplete as well, you need to go with unofficial opencv.
I had the same issue. This helps me:
conda install -c menpo opencv3
Found at https://www.scivision.co/install-opencv-python-windows/

Python: Why can't I import svm? [duplicate]

Using Python 2.7 with scikit-learn 0.14 package. It runs well on some examples from the user guild expect the Linear Models.
Traceback (most recent call last):
File "E:\P\plot_ols.py", line 28, in <module>
from sklearn import datasets, linear_model
File "C:\Python27\lib\site-packages\sklearn\linear_model\__init__.py", line 12, in <module>
from .base import LinearRegression
File "C:\Python27\lib\site-packages\sklearn\linear_model\base.py", line 29, in <module>
from ..utils.sparsefuncs import mean_variance_axis0, inplace_column_scale
ImportError: cannot import name inplace_column_scale
Thank you~
I was able to fix this by going to my python folder and deleting the file:
python27\Lib\site-packages\sklearn\utils\sparsefuncs.pyd
My guess is that the problem was:
An older version of scikit-learn implemented sparsefuncs as a windows DLL
The current version implements it as a python file
If you install a new version on top of an old version it does not delete the old DLL
When you try to import, Python uses the pyd in preference to the py implementation
But the old implementation did not include this function
This suggests that there might be bigger problems caused by installing a new version and it might be wise to delete the whole sklearn directory before reinstalling the new version.
I encountered the same issue in Mac Os.
I solved it by deleting the file manually:
rm /usr/local/lib/python2.7/site-packages/sklearn/utils/sparsefuncs.so
Uninstalling scikit-learn and reinstalling it was the only option that worked for me:
pip uninstall scikit-learn
pip install scikit-learn
I solve this problem by :
pip uninstall scikit-learn
and don't forget to rm the 'sklearn' folder in the python 'site-packages'
rm -rf /path/Python-2.7.5/lib/python2.7/site-packages/sklearn/
then reinstall the package:
pip install scikit-learn
On a related note, this has been posted as a bug on the official Github page, along with some additional solutions, basically suggesting the same solutions as above. Long story short: run a make clean to get rid of the .so file.
I had the same problem. I had originally installed scikit-learn by:
sudo apt-get install python-sklearn
When none of the other solutions posted here worked, I decided to uninstall my version of scikit-learn and reinstall it:
pip2 install --user --install-option="--prefix=" -U scikit-learn
Used pip2 because I have two versions of python, so I use scikit-learn in Python 2.7
same problem happened with can not import _safe_split, have a look
http://stackoverflow.com/questions/41024001/importerror-cannot-import-name-safe-split
https://github.com/scikit-learn/scikit-learn/issues/7582
EDIT: check comment by Andreas Mueller

problems installing M2Crypto on Mint: follow-up

I asked a question here regarding installing the M2Crypto python library in Mint. That question was answered successfully and I was able to build and install M2Crypto. However, I am not able to use it within Python. when I attempt to import the module, I get the following error:
>>> import M2Crypto
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/M2Crypto/__init__.py", line 22, in <module>
import __m2crypto
ImportError: /usr/local/lib/python2.7/dist-packages/M2Crypto/__m2crypto.so: undefined symbol: SSLv2_method
If anyone know how to resolve this error, please let me know.
After two years the problem in m2crypto0.21.1 still exists, so here is a note for Ubuntu users. If you're not using virtualenv, you can easily fix it by installing m2crypto from Ubuntu PPA instead of pip:
sudo pip uninstall m2crypto
sudo apt-get install python-m2crypto
Seems like the problem is fixed in the PPA, but not in the project's repo. At least it worked for me at Ubuntu 12.04.
To expand the answer above:
This is a bug in M2Crypto 0.21.1. It has to do with the fact that SSLv2 was removed from OpenSSL on many platforms on the grounds of it being too insecure, notably Debian [1] and Ubuntu.
The removal is not detected during compile. There is a widely available patch that fixes this. I incorporated this into the M2Crypto source code on Github.
You can use pip to install directly from the repository like so:
pip install -e git+https://github.com/Hypernode/m2crypto#egg=M2Crypto
For those who want to inspect the (much published) patch that fixes this: b432d36
Edit: moved to another location
It looks like it is a bug introduced in M2Crypto 0.21.1, there is a patch here that correct the problem.
Maybe you could try to install an old version of M2Crypto (like the 0.20.1-1.1) or apply the patch manually with the patch command.

Categories