1

I am trying to use NLTK and am able to do so using python2.7, but I am unable to use it with python3 (i.e. when I type import nltk, I get the following error message:

ModuleNotFoundError: No module named 'nltk' I have Googled for how to install NLTK with python3 and none of the solutions I've found worked for me:

  1. This solution suggests running pip3 install -U nltk. When I do so everything starts going fine until a lengthy red error message starting with ERROR: Command errored out with exit status 1: (see full message copied at the bottom if it's relevant).

  2. A couple solutions are offered here. The first is to type sudo apt install python3-nltk. When I do so I get this message: Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/bin/apt" (-1).

The second solution therein is quite similar to 1. but with sudo: sudo pip3 install nltk. This generates the same long error message mentioned above.

My understanding is that the above solutions are for Ubuntu rather than Mac users. Can someone please advise how to get around one of these issues or how to install NLTK with python3 on Mac? Thank you in advance!

I am running macOS Catalina version 10.15.4. My current version of python is 3.7.4.

ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/setup.py'"'"'; __file__='"'"'/private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-wheel-197yegm_
       cwd: /private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/
  Complete output (17 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.14-x86_64-3.7
  creating build/lib.macosx-10.14-x86_64-3.7/regex
  copying regex_3/__init__.py -> build/lib.macosx-10.14-x86_64-3.7/regex
  copying regex_3/regex.py -> build/lib.macosx-10.14-x86_64-3.7/regex
  copying regex_3/_regex_core.py -> build/lib.macosx-10.14-x86_64-3.7/regex
  copying regex_3/test_regex.py -> build/lib.macosx-10.14-x86_64-3.7/regex
  running build_ext
  building 'regex._regex' extension
  creating build/temp.macosx-10.14-x86_64-3.7
  creating build/temp.macosx-10.14-x86_64-3.7/regex_3
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c regex_3/_regex.c -o build/temp.macosx-10.14-x86_64-3.7/regex_3/_regex.o
  xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  error: command 'clang' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for regex
  Running setup.py clean for regex
Failed to build regex
Installing collected packages: regex, nltk
    Running setup.py install for regex ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/setup.py'"'"'; __file__='"'"'/private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-record-szrtsqap/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/regex
         cwd: /private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/
    Complete output (17 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.14-x86_64-3.7
    creating build/lib.macosx-10.14-x86_64-3.7/regex
    copying regex_3/__init__.py -> build/lib.macosx-10.14-x86_64-3.7/regex
    copying regex_3/regex.py -> build/lib.macosx-10.14-x86_64-3.7/regex
    copying regex_3/_regex_core.py -> build/lib.macosx-10.14-x86_64-3.7/regex
    copying regex_3/test_regex.py -> build/lib.macosx-10.14-x86_64-3.7/regex
    running build_ext
    building 'regex._regex' extension
    creating build/temp.macosx-10.14-x86_64-3.7
    creating build/temp.macosx-10.14-x86_64-3.7/regex_3
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c regex_3/_regex.c -o build/temp.macosx-10.14-x86_64-3.7/regex_3/_regex.o
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/setup.py'"'"'; __file__='"'"'/private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-install-s1y993sb/regex/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/9f/g32_gdr143v5rd3c83875ljc0000gn/T/pip-record-szrtsqap/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/regex Check the logs for full command output.
nohillside
  • 100,768
  • apt is the annotation processing tool on macOS :-) – nohillside Jun 10 '20 at 15:11
  • The answer linked to on the top should take care of the obvious error. If it still doesn't work, please ask a new question (linking back to this one) and add the new output you get. – nohillside Jun 10 '20 at 15:20

0 Answers0