Littlest JupyterHub TextBlob Installation - ModuleNotFoundError

Hello, friends. First-time JupyterHub user here, starting off with The Littlest JupyterHub. We had a successful install using the instructions at tljh.jupyter.org, but when I tried to install the TextBlob module from instructions at textblob.readthedocs.io, TLJH insists there’s no such module—

ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import TextBlob

ModuleNotFoundError: No module named ‘TextBlob’

It appears that TextBlob was installed, because when I see something in /opt/tljh/user/lib/python3.7/site-packages, /opt/conda/lib/python3.8/site-packages, and in my home directory’s .local/lib/python2.7 directory. My path includes /opt/tljh/user/bin, where there is python3.7, so right now I’m not seeing where the environment has gone wrong. Any tips?

Not really following where you are working and trying what in your description.
I think you are saying you installed it from instructions somewhere other than The Littlest JupyterHub instructions? To install pip installable packages, you’d follow the Littlest JupyterHub instructions guide to Installing pip packages here.
Try that. Then use the the dashboard, the place where selected a New terminal according to the image there, except now try opening a new Python 3 notebook from the dashboard. In that new notebook, your import command should now work.

I did try installing it as a pip package (using sudo -E pip install textblob in the Notebook Terminal), but it doesn’t look like these instructions work—admin users are supposed to have “full root access to the server with passwordless sudo”, but this does not appear to be the case.

Are you saying to don’t have root access with passwordless sudo? You should. (Although I haven’t tried in a few months.)
That more than likely indicates an issue.

Had you seen this thread? This solution turned out to be an #includedir statement not being on a separate line. Any chance you have something similar?

I just minutes ago found that thread and implemented the fix, and now have proper passwordless sudo. Was able to run…

sudo -E pip install textblob
python -m textblob.download-corpora

…but I was still unable to get a TextBlob import into a Notebook. Also tried using…

conda install -c conda-forge textblob

…also without success. The response is always “ModuleNotFoundError: No module named ‘TextBlob’”, even though I can see it right there in /opt/tljh/user/lib/python3.7/site-packages, and even though my PATH (/opt/tljh/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin) appears to point to the right place.

It’s a head-scratcher, but if I scratch any harder I’ll start to lose my hair.

Fixing the proper passwordless sudo was good progress though as that was going to continue to be an issue.
I wonder if putting sudo -E in front of the second step would help at all? sude -E python -m textblob.download-corpora

Then after trying the suggestion, I’d try try running the following inside a notebook cell when you signed in as admin account.

%conda install -c conda-forge textblob

Then see if you can import in the cell after that one.

Running this command from inside a notebook cell produced a warning that conda should be updated, and then an error—

EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
environment location: /opt/tljh/user
uid: 1001
gid: 1003

I instead ran sudo -E conda update -n base -c defaults conda from a Jupyter terminal, and then sudo -E conda install -c conda-forge textblob, but this changed nothing. However, the mention of permissions led me to take a peek in /opt/tljh/user, and some files are owned by my Jupyter admin user and not root, including textblob. I don’t think this matters with permissions of drwxr-xr-x, but let me know if I’m wrong.

At this point the module appears to be installed, but for some reason TLJH cannot see it. If there was an error in /etc/sudoers, could there be an error in another file on which TLJH depends that is preventing it from seeing any new modules?

Textblob is unusual having that extra but that needs to be run when you pip install it. So I’d be interested if you are able to install other modules you have yet to install so that you could know if it is all modules you continue to try to install? (Suggestions I know are good that maybe you don’t have already: biopython or seaborn.) Or is the issue possibly just this module or modules you already tried installing?

Yes, I’m worried you really did a number on your original system when you didn’t have passwordless sudo enabled. (I’m still concerned why that seems to happen to more than one person recently.) I normally test things on a cloud system and then start fresh when things go haywire. Or maybe you could at least test on a fresh setup elsewhere?

Well, I did spin up a fresh instance of TLJH, and after fixing the sudoers error I ran sudo -E conda install -c conda-forge textblob followed by sudo -E python -m textblob.download_corpora. Going into the notebook to import TextBlob once again produced a ModuleNotFoundError. I also tried upgraded TextBlob to the latest version ( pip install -U git+https://github.com/sloria/TextBlob.git@dev), but this changed nothing.

At least this time the directory ownership looks correct.

Meanwhile, installing biopython went fine. I installed it, and in an available cell typed import Bio and help(Bio), which produced the helpfile. It works just fine! So this is even more vexing—I don’t think that TextBlob works with Jupyter Notebooks but is incompatible with JupyterHub, as I can’t imagine I’d be the first to notice.

One thing I know is that sometimes the system needs additional dependencies that conda and pip cannot handle. For example, this is the purpose of the apt.txt configuration file when making repos Binder-ready, see here. Sadly, I don’t know anything more about TextBlob to advise if that is the case here. Sorry.

For now, I’ve changed the name of the thread to better reflect the current TextBlob install issue. Maybe someone else will have some insight.

In this post (and here), I see the import statement run like below and then it gives a more detailed error report:

from textblob import TextBlob

Have you tried that and does it provide more details?

For example, in that post it seemed it needed to use apt to install things like libsqlite3-dev first.

You know, I just started poking around on GitHub and had failed to omit is:open from my search. Facepalm.

As it happens, on two of my test instances, when I try from textblob import TextBlob in my test environment I got nothing at all instead of an error. After entering this I can then go on to get TextBlob responses using the examples in the TextBlob Quickstart tutorial. This looks like proper behavior.

If this really is TextBlob working properly, I can go back through my notes and find actions to take to repair the current install (one of these two instances was built in the same erroneous fashion, working around a broken sudoers file, as the live server). Failing that, I can migrate my director & his class to a working server. I’m going to work on this for a bit, then with any luck come back and wrap up this discussion. :crossed_fingers:

1 Like