No module named 'nltk.lm' in Google colaboratory - google-cloud-platform

I'm trying to import the NLTK language modeling module (nltk.lm) in a Google colaboratory notebook without success. I've tried by installing everything from nltk, still without success.
What mistake or omission could I be making?
Thanks in advance.
.

Google Colab has nltk v3.2.5 installed, but nltk.lm (Language Modeling package) was added in v3.4.
In your Google Colab run:
!pip install -U nltk
In the output you will see it downloads a new version, and uninstalls the old one:
...
Downloading nltk-3.6.5-py3-none-any.whl (1.5 MB)
...
Successfully uninstalled nltk-3.2.5
...
You must restart the runtime in order to use newly installed versions.
Click the Restart runtime button shown in the end of the output.
Now it should work!
You can double check the nltk version using this code:
import nltk
print('The nltk version is {}.'.format(nltk.__version__))
You need v3.4 or later to use nltk.lm.

Related

OpenCv is pre-installed in google Colab, but i want to add one extra module from opencv_contrib. how to achieve this?

I am working on google Colab and for the pre-installed opencv the functionality works fine, but i want to use "BRISQUE" which is not fully released but can be installed with opencv-contrib. There are methods which are followed but they are not for google colab. So not working for me.I actually want "quality" module from opencv-contrib to be appended to my opencv. The link to the module is https://github.com/opencv/opencv_contrib/tree/master/modules/quality
Screenshot of sample program is attached which is giving error..
Any help would be appreciated.
Thanks in advance.
!pip install opencv-python==3.4.2.17
!pip install opencv-contrib-python==3.4.2.17
import cv2
this worked for me. Load cv2 in the same cell. IF you load seperately, it takes a default version

install be_helper on datalab

I knew that BigQuery module is already installed on datalab. I just wanna to use bq_helper module because I learned it on Kaggle.
I did !pip install -e git+https://github.com/SohierDane/BigQuery_Helper#egg=bq_helper and it worked.
but I can't import the bq_helper. The pic is shown below.
Please help. Thanks!
I used python2 on Datalab.
I am not familiar with the BigQuery Helper library you shared, but in general, in Datalab, it may happen that you need to restart the kernel in order for the libraries to be properly loaded.
I reproduced the scenario you proposed: installing the library with the command !pip install -e git+https://github.com/SohierDane/BigQuery_Helper#egg=bq_helper and then trying to import it in the notebook using:
from bq_helper import BigQueryHelper
bq_assistant = BigQueryHelper("bigquery-public-data", "github_repos")
bq_assistant.project_name
At first, it did not work and I obtained the same error as you; then I clicked on the Reset Session button and the library was loaded properly.
Some other details that may be relevant if this does not work for you are:
I am also running on Python2 (although the GitHub page of the library suggests that it was only tested in Python3.6+).
The Custom metadata parameters in the Datalab GCE instance are: created-with-datalab-version: 20180503 and created-with-sdk-version: 208.0.2.

Installing Python 2.7 for all users on SLES 11

I installed Python 2.7 on SLES 11 box that previously was running Python 2.6. To do so I used a script described in this post and run it as a root user. Everything went well but when it was done I discovered few issues:
No symbolic links were created and no path updated so I had to manually update the path to link to the new installation bin directory /opt/python2.7/bin
Everything runs good until I switch from root to the normal user at which point Python shell runs but some modules I installed such as PyYAML are missing. Again, these are OK when I run Python as root
As a regular user I'm not able to run pip, easy_install and wheel. For pip I get ImportError: No module named pkg_resources
P.S. Following #user suggestion I tried adding the following path taken from sys.path of the root user to .bashrc which did not fix the problem
export PYTHONPATH=$PYTHONPATH:/opt/python2.7/lib/python27.zip:/opt/python2.7/lib/python2.7:/opt/python2.7/lib/python2.7/plat-linux2:/opt/python2.7/lib/python2.7/lib-tk:/opt/python2.7/lib/python2.7/lib-old:/opt/python2.7/lib/python2.7/lib-dynload:/opt/python2.7/lib/python2.7/site-packages:/opt/python2.7/lib/python2.7/site-packages/PyYAML-3.11-py2.7-linux-x86_64.egg:/opt/python2.7/lib/python2.7/site-packages/pexpect-4.2.0-py2.7.egg:/opt/python2.7/lib/python2.7/site-packages/ptyprocess-0.5.1-py2.7.egg
Credible / official sources: no reply from official forum. Apart from the SO-link you mentioned, there is also https://unix.stackexchange.com/questions/7644/how-to-do-a-binary-install-of-python-2-7-on-suse-linux-enterprise-server-11, which sketches the way to do it described in Installing Python 2.7 on SLES 11 (SO is not official, is it? ;-)
Concerning your problem: both 2. and 3. might be caused by elements lacking in sys.path.
To test this, type
import sys; sys.path
both in user and root python and check for differences. These need to be merged. Try using PYTHONPATH first to test this, but be aware that there are different methods how to adjust sys.path.
If you just need to fix this for normal (non-daemon) users, adjusting the system-wide bash profile would be an easy solution.
(Any questions/feedback is welcome... :-)

NLTK Wordnet Download Out of Date

New to Python, tying to get started with NLTK. After a rough time installing Python on my Windows 7 64-bit system, I am now having a rough time downloading Wordnet and other NLTK data packages located here:
http://nltk.org/nltk_data/
Some packages download, some say "Out of Date"
import nltk
nltk.download()
When I use the above to download, the program doesn't let me cancel if I hit the cancel button.
So, I just shut it down and go directly to the link above to try and download it manually. When I try to download Wordnet for example, the download starts in my browser but stops mid-way through download!
This is very frustrating for me as a beginner. Is there an alternative way to download Wordnet for nltk?
I was facing the same issue. The issue in my case was that when the NLTK downloader started it had the server index as
http://nltk.github.com/nltk_data/
This needs to be changed to
http://nltk.org/nltk_data/
You can change this by going into the NLTK Downloader window and the File->Change Server Index.
Regards,
Bonson

pyspeech not working in python 2.7

I want to make and explore the speech to text using the python. So I searched on the google about the python speech to text api I have found pyspeech at the first and found it much easy to use but even after installing it I got some problems.
1) I have installed pyspeech using command prompt easy_install speech at the c:>python27...scripts but still i am unable to run the python speech API.
2) I have also installed the base PyPI required for the pyspeech running ez_setup.py.
What is the import error you get? pyspeech also needs pywin32.
Is that package installed? Also check if Microsoft speech kit is installed.
If everything is fine, add sys.path.append(site package path) at the top of your code.