title: Python NLTK: SyntaxError: Non-ASCII character '\xc3' in file (Sentiment Analysis -NLP)
body: <p>I am playing around with NLTK to do an assignment on sentiment analysis. I am using Python 2.7. NLTK 3.0 and NumPy1.9.1 version. </p>
  
  <p>This is the code :</p>
  
  <pre><code>__author__ = 'karan'
  import nltk
  import re
  import sys
  
  
  
  def main():
      print("Start");
      # getting the stop words
      stopWords = open("english.txt","r");
      stop_word = stopWords.read().split();
      AllStopWrd = []
      for wd in stop_word:
          AllStopWrd.append(wd);
      print("stop words-&gt; ",AllStopWrd);
  
      # sample and also cleaning it
      tweet1= 'Love, my new toyí ½í¸í ½í¸#iPhone6. Its good https://twitter.com/Sandra_Ortega/status/513807261769424897/photo/1'
      print("old tweet-&gt; ",tweet1)
      tweet1 = tweet1.lower()
      tweet1 = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"," ",tweet1).split())
      print(tweet1);
      tw = tweet1.split()
      print(tw)
  
  
      #tokenize
      sentences = nltk.word_tokenize(tweet1)
      print("tokenized -&gt;", sentences)
  
  
      #remove stop words
      Otweet =[]
      for w in tw:
          if w not in AllStopWrd:
              Otweet.append(w);
      print("sans stop word-&gt; ",Otweet)
  
  
      # get taggers for neg/pos/inc/dec/inv words
      taggers ={}
      negWords = open("neg.txt","r");
      neg_word = negWords.read().split();
      print("ned words-&gt; ",neg_word)
      posWords = open("pos.txt","r");
      pos_word = posWords.read().split();
      print("pos words-&gt; ",pos_word)
      incrWords = open("incr.txt","r");
      inc_word = incrWords.read().split();
      print("incr words-&gt; ",inc_word)
      decrWords = open("decr.txt","r");
      dec_word = decrWords.read().split();
      print("dec wrds-&gt; ",dec_word)
      invWords = open("inverse.txt","r");
      inv_word = invWords.read().split();
      print("inverse words-&gt; ",inv_word)
      for nw in neg_word:
          taggers.update({nw:'negative'});
      for pw in pos_word:
          taggers.update({pw:'positive'});
      for iw in inc_word:
          taggers.update({iw:'inc'});
      for dw in dec_word:
          taggers.update({dw:'dec'});
      for ivw in inv_word:
          taggers.update({ivw:'inv'});
      print("tagger-&gt; ",taggers)
      print(taggers.get('little'))
  
      # get parts of speech
      posTagger = [nltk.pos_tag(tw)]
      print("posTagger-&gt; ",posTagger)
  
  main();
  </code></pre>
  
  <p>This is the error that I am getting when running my code:</p>
  
  <pre><code>SyntaxError: Non-ASCII character '\xc3' in file C:/Users/karan/PycharmProjects/mainProject/sentiment.py on line 19, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
  </code></pre>
  
  <p>How do I fix this error?</p>
  
  <p>I also tried the code using Python 3.4.2 and with NLTK 3.0 and NumPy 1.9.1 but then I get the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/karan/PycharmProjects/mainProject/sentiment.py", line 80, in &lt;module&gt;
      main();
    File "C:/Users/karan/PycharmProjects/mainProject/sentiment.py", line 72, in main
      posTagger = [nltk.pos_tag(tw)]
    File "C:\Python34\lib\site-packages\nltk\tag\__init__.py", line 100, in pos_tag
      tagger = load(_POS_TAGGER)
    File "C:\Python34\lib\site-packages\nltk\data.py", line 779, in load
      resource_val = pickle.load(opened_resource)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xcb in position 0: ordinal not in range(128)
  </code></pre>