Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 branch does not work with python 3(.5) Fix is here #46

Closed
remibolcom opened this issue Feb 2, 2016 · 3 comments
Closed

Python3 branch does not work with python 3(.5) Fix is here #46

remibolcom opened this issue Feb 2, 2016 · 3 comments

Comments

@remibolcom
Copy link

Hi Saffsd,

langid fails on line 167 of langid.py with the very example provided on the front page.
This is because in python3, dividing integers produces a float. The fix is to change line 163 from

nb_numfeats = len(nb_ptc) / len(nb_pc)

to

nb_numfeats = int(len(nb_ptc) / len(nb_pc))

and to change line 167 to this:

nb_ptc = np.array(nb_ptc).reshape(nb_numfeats, len(nb_pc))

This fix should be easy to make.
Thanks.

@saffsd saffsd closed this as completed in 2acad6b Mar 8, 2016
@saffsd
Copy link
Owner

saffsd commented Mar 8, 2016

Hi remibolcom, thanks for reporting the issue and sorry it has taken me so long to address it. I (strangely) don't seem to be able able to reproduce the issue on either the python3 branch or the master branch. Nonetheless, I take your point and I've updated the master branch accordingly. I hope to delete the python3 branch at some point - the main langid.py classifier in master should be compatible with both python2 and python3.

@kellymarchisio
Copy link

FYI, I just got this error using the conda install.

conda create -n wmt18-filtering python=3.6 numpy
source activate wmt18-filtering
conda install -c activisiongamescience langid
langid

Results in:

Traceback (most recent call last): File "/home/kmarc/anaconda3/envs/wmt18-filtering/bin/langid", line 6, in <module> sys.exit(langid.langid.main()) File "/home/kmarc/anaconda3/envs/wmt18-filtering/lib/python3.5/site-packages/langid/langid.py", line 498, in main identifier = LanguageIdentifier.from_modelstring(model, norm_probs = options.normalize) File "/home/kmarc/anaconda3/envs/wmt18-filtering/lib/python3.5/site-packages/langid/langid.py", line 182, in from_modelstring nb_ptc = np.array(nb_ptc).reshape(len(nb_ptc)/len(nb_pc), len(nb_pc)) TypeError: 'float' object cannot be interpreted as an integer

@bm777
Copy link

bm777 commented Jan 12, 2024

FYI, I just got this error using the conda install.

conda create -n wmt18-filtering python=3.6 numpy source activate wmt18-filtering conda install -c activisiongamescience langid langid

Results in:

Traceback (most recent call last): File "/home/kmarc/anaconda3/envs/wmt18-filtering/bin/langid", line 6, in <module> sys.exit(langid.langid.main()) File "/home/kmarc/anaconda3/envs/wmt18-filtering/lib/python3.5/site-packages/langid/langid.py", line 498, in main identifier = LanguageIdentifier.from_modelstring(model, norm_probs = options.normalize) File "/home/kmarc/anaconda3/envs/wmt18-filtering/lib/python3.5/site-packages/langid/langid.py", line 182, in from_modelstring nb_ptc = np.array(nb_ptc).reshape(len(nb_ptc)/len(nb_pc), len(nb_pc)) TypeError: 'float' object cannot be interpreted as an integer


Hi @kellymarchisio ,
You should use the workaround of @remibolcom

This is because in python3, dividing integers produces a float. The fix is to change line 163 from

nb_numfeats = len(nb_ptc) / len(nb_pc)

to

nb_numfeats = int(len(nb_ptc) / len(nb_pc))

and to change line 167 to this:

nb_ptc = np.array(nb_ptc).reshape(nb_numfeats, len(nb_pc))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants