explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
30.13k stars 4.4k forks source link

Spacy installed but not able to import error: unknown locale: UTF-8 #2570

Closed nikhilsharma010 closed 6 years ago

nikhilsharma010 commented 6 years ago

I installed Spacy and initially I encountered errors with installation but those have been fixed thanks to I looked at earlier queries. Still I when I do import spacy on jupyter I get ValueError: unknown locale: UTF-8

But in my terminal it shows it is installed

Nikhils-MacBook-Air:~ nikhil$ sudo python -m spacy download en Password: Collecting https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz Downloading https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz (37.4MB) 100% |████████████████████████████████| 37.4MB 1.7MB/s Requirement already satisfied (use --upgrade to upgrade): en-core-web-sm==2.0.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz in /anaconda3/lib/python3.6/site-packages

Linking successful
/anaconda3/lib/python3.6/site-packages/en_core_web_sm -->
/anaconda3/lib/python3.6/site-packages/spacy/data/en

You can now load the model via spacy.load('en')


* Operating System: mac os 10.13.5
* Python Version Used: 3.6
* spaCy Version Used: 2.0.11
ines commented 6 years ago

This should hopefully be easy to resolve – see this section in the troubleshooting guide:

ValueError: unknown locale: UTF-8

This error can sometimes occur on OSX and is likely related to a still unresolved Python bug. However, it's easy to fix: just add the following to your ~/.bash_profile or ~/.zshrc and then run source ~/.bash_profile or source ~/.zshrc. Make sure to add both lines for LC_ALL and LANG.

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
nikhilsharma010 commented 6 years ago

I already did that

Nikhils-MacBook-Air:~ nikhil$ sudo nano ~/.bash_profile Password: Nikhils-MacBook-Air:~ nikhil$ source ~/.bash_profile Nikhils-MacBook-Air:~ nikhil$ cat ~/.zshrc cat: /Users/nikhil/.zshrc: No such file or directory Nikhils-MacBook-Air:~ nikhil$ sudo nano ~/.zshrc Nikhils-MacBook-Air:~ nikhil$ source export LC_ALL=en_US.UTF-8 -bash: export: No such file or directory Nikhils-MacBook-Air:~ nikhil$ export LANG=en_US.UTF-8 Nikhils-MacBook-Air:~ nikhil$ source ~/.zshrc Nikhils-MacBook-Air:~ nikhil$

still I am getting the same error while importing

ines commented 6 years ago

Could you run the locale command in your terminal and share the output?

nikhilsharma010 commented 6 years ago

Nikhils-MacBook-Air:~ nikhil$ locale LANG="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_ALL="en_US.UTF-8" Nikhils-MacBook-Air:~ nikhil$

ines commented 6 years ago

That all looks correct. Is that the same in Jupyter? Maybe the problem is that your Juypter environment uses different locale settings. You could try the following to check:

import locale
print(locale.getlocale())
nikhilsharma010 commented 6 years ago

When I run this in Jupyer notebook

I get the same error.


ValueError Traceback (most recent call last)

in () 1 import locale ----> 2 print(locale.getlocale()) /anaconda3/lib/python3.6/locale.py in getlocale(category) 579 if category == LC_ALL and ';' in localename: 580 raise TypeError('category LC_ALL is not supported') --> 581 return _parse_localename(localename) 582 583 def setlocale(category, locale=None): /anaconda3/lib/python3.6/locale.py in _parse_localename(localename) 488 elif code == 'C': 489 return None, None --> 490 raise ValueError('unknown locale: %s' % localename) 491 492 def _build_localename(localetuple): ValueError: unknown locale: UTF-8
nikhilsharma010 commented 6 years ago

When I run the same command in my terminal it gives back the following and runs without error

import locale print(locale.getlocale()) ('en_US', 'UTF-8') import spacy nlp = spacy.load('en')

But in Jupyter this isn't working giving the same error

Also I am new to programming and python so may be some of the issues might be easy but i may not be able to figure that out. I think this is an environment issue can you help redirect in the right direction to solve that

nikhilsharma010 commented 6 years ago

The issue is solved when I used following command

Nikhils-MacBook-Air:~ nikhil$ sudo conda install -c conda-forge spacy

now if I do import spacy it works fine however

if I write

nlp = spacy.load('en')

it given me Keyerror: 'package'

ines commented 6 years ago

Glad you got the locale thing working! I'm surprised this worked, but maybe conda actually fixed the locale stuff in your environment when you reinstalled spaCy 🙂 I'll answer the other question in #2571.

yaliagap commented 6 years ago

@nikhilsharma010 Thank you for your command script. That's work for me.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.