Python Forum
Please help: problem installing/importing langdetect module in Jupyter Notebook
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help: problem installing/importing langdetect module in Jupyter Notebook
#1
Hello, I would like to start by letting you know that I am a layperson. I only started working with Python a few weeks ago, so I am new to this. I would be very grateful for your help!

I want to test out Omar Einea's Goodreads Reviews Scraper (https://github.com/OmarEinea/GoodReadsScraper). I followed his instructions and installed beautifulsoup4, langdetect, selenium and lxml.
I copy-pasted part of his code from reviews.py to a Jupyter Notebook to test it out and ran the following cell:

from Tools import SafeThread
from bs4 import BeautifulSoup
from langdetect import detect
from Browser import Browser
from Writer import Writer
However, I got the following error:

Error:
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) <ipython-input-5-f57bdcb0fa9c> in <module> 1 from Tools import SafeThread 2 from bs4 import BeautifulSoup ----> 3 from langdetect import detect 4 from Browser import Browser 5 from Writer import Writer ModuleNotFoundError: No module named 'langdetect'
I thought that perhaps I hadn't installed langdetect correctly, so I ran
 pip install langdetect 
in the command line again, but I received the message that it had already been installed:

Requirement already satisfied: langdetect in c:\users\XXX\appdata\local\programs\python\python38-32\lib\site-packages (1.0.7)
Requirement already satisfied: six in c:\users\XXX\appdata\local\programs\python\python38-32\lib\site-packages (from langdetect) (1.13.0)
Do you have any ideas on how I might be able to solve this problem?
Thank you in advance for your help and understanding!
Reply
#2
Test that it work from command line and then you most check that same Python interpreter is set in PyCharm.
A common problem is that you can be using eg Anaconda with Jupyter Notebook,the it will point to that Python interpreter.
You can also install langdetect to Anaconda as shown under here.
(forum_env) E:\div_code\forum_env
λ pip install langdetect
Collecting langdetect
  Downloading ....
Successfully installed langdetect-1.0.7

# Test 
(forum_env) E:\div_code\forum_env
λ ptpython
>>> from langdetect import detect
# No errors

>>> detect.__code__
<code object detect at 0x04C2BBD0, file "e:\div_code\forum_env\lib\site-packages\langdetect\detector_factory.py", line 126>
For you this is the Base interpreter.
c:\users\XXX\appdata\local\programs\python\python38-32
The Python executable if need to point that.
c:\users\XXX\appdata\local\programs\python\python38-32\python.exe
Reply
#3
I am having this same problem in visual studio. I managed to awitch envronments back from 3 version to 2.7. Then I switched versions in the command line prompt thinking I would have to reinstall all the packages from 3 but I am getting the same "satifaction" respomse from the prompt. I get this error:

File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\17138\source\repos\NLTK\Tokenizing.py", line 5, in <module>
from nltk.tokenize import sent_tokenize, word_tokenize
ImportError: No module named nltk.tokenize
The thread 'MainThread' (0x1) has exited with code 0 (0x0).
The program 'pythonw.exe' has exited with code 0 (0x0).

With this code:

from nltk.tokenize import sent_tokenize, word_tokenize

sample_text = "Hello Mr. Smith, how are you? How are you doing today the weather is great and python is awesome. The sky is blue and you should not eat cardboard."

print(sent_tokenize(sample_text))
Reply
#4
Usually that indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check sys.executable to see which Python it's running in, and sys.path to see where it's looking for imports.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ERROR WHILE INSTALLING PLAYSOUND MODULE satwants33 2 1,030 Mar-23-2024, 12:50 PM
Last Post: Ritik2508
Photo Problem installing turtle MasterJediKnight7 17 24,299 Mar-18-2024, 10:22 AM
Last Post: bmohamadyar313
  problem with memory_graph module akbarza 3 294 Mar-04-2024, 10:15 AM
Last Post: snippsat
  importing variables from module 8376459 1 245 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  problem using coloeama module akbarza 3 512 Jan-08-2024, 07:31 AM
Last Post: akbarza
  no module named 'docx' when importing docx MaartenRo 1 705 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 872 Nov-15-2023, 06:56 PM
Last Post: jst
  Navigating file directories and paths inside Jupyter Notebook Mark17 5 626 Oct-29-2023, 12:40 PM
Last Post: Mark17
  problem in using subprocess module akbarza 5 944 Sep-24-2023, 02:02 PM
Last Post: snippsat
  problem in import module from other folder akbarza 5 1,257 Sep-01-2023, 07:48 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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