Python Forum
[split] serious n00b.. NLTK in python 2.7 and 3.5
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] serious n00b.. NLTK in python 2.7 and 3.5
#1
Hi All,

I am a python noob (comparable to when this thread was first started) trying to get NLTK up and running as my first Python application.

I have both python 2.7.10 and 3.6.4 installed. I think I somehow installed NLTK into the wrong version of Python and I have been unable to get the NLTK module in python3. I have installed a bunch of packages in Python3 (matplotlib, math, numpy) and want to make sure I am ONLY coding in Python3 going forward.

Any help getting my foundation right would be really helpful! I'm in circles now with the python version -- module install alignment.

From Terminal:

--- python --- module is found

Kevins-MBP:~ kevin$ python
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>

--- python3 --- module not found

Kevins-MBP:~ kevin$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nltk'
>>>
Reply
#2
Have you tried pip3 install module_name or perhaps pip3.6 install module_name ?

If you are getting an error, please post the entire error (between the error tags)
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
You could have mention that you use Mac.
Doing it Right
Quote:Homebrew installs pip3 for you.
pip3 is the alias to pip pointing to the Homebrew’d Python 3.

I would mention pyenv the best version management to use,
and safe it do not mess with system Python installation.

Examle Linux,work the same on Mac.
# Install
mint@mint ~ $ pyenv install 3.6.4
Downloading Python-3.6.4.tar.xz...
-> https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
Installing Python-3.6.4...
Installed Python-3.6.4 to /home/mint/.pyenv/versions/3.6.4

# Set python and pip to point to 3.6.4
mint@mint ~ $ pyenv global 3.6.4
mint@mint ~ $ python -V
Python 3.6.4
mint@mint ~ $ pip -V
pip 9.0.1 from /home/mint/.pyenv/versions/3.6.4/lib/python3.6/site-packages (python 3.6)
# Finish
Reply
#4
Thanks for the responses! Sorry snippsat, will try to add more relevant info to future posts.

For background, I successfully followed all of the steps here to get Python3 setup: How To Install Python 3 and Set Up a Local Programming Environment on macOS. This included setting up an environment to manage python projects. Is pyenv a better way to do what they recommended in "Step 5 — Creating a Virtual Environment"?

@sparkz_alot - I tried
pip3 install nltk
and it seems to think the package is already there. When I fire up python3 and try to import nltk, it says it cannot find it.

I think I maybe installed nltk in an environment I had set up at the link below? I am just getting familiar with all this, so it's possible I implemented the environment but am failing to navigate it properly.

Kevins-MBP:~ kevin$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
Kevins-MBP:~ kevin$ pip3 install nltk
Requirement already satisfied: nltk in /usr/local/lib/python3.6/site-packages
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from nltk)
Kevins-MBP:~ kevin$ python3
Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nltk'
>>> 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on trying to use NLTK Punkt PythonDE 1 2,046 Oct-22-2020, 07:17 PM
Last Post: PythonDE
  [nltk] Parsing with CFG constantin01 1 2,096 Jul-05-2019, 11:11 PM
Last Post: Larz60+
  [nltk] Relations Extractor constantin01 3 3,509 Jun-28-2019, 10:41 AM
Last Post: constantin01
  [nltk] Naive Bayes Classifier constantin01 0 1,992 Jun-24-2019, 10:36 AM
Last Post: constantin01
  NLTK Download Attribute error laila1a 1 8,576 Jan-27-2019, 12:03 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020