jehfoori
jehfoori

Reputation: 11

Can't import NLTK into Jupyter Notebook

I'm pretty new to python, Jupyter notebook, Tensorflow, and that whole lot in general. I'm getting started with a machine learning project. I've gotten to the point where I want to import "nltk" into my thing. It doesn't work. I've installed nltk with pip, and conda, and everything, in my terminal. When I do it again in the notebook, it says I've already installed it, which is correct. But when I try to import it it gives me a ModuleNotFoundError:

1

I'm on a macbook, by the way. Any help?

Upvotes: 1

Views: 971

Answers (1)

Bitswazsky
Bitswazsky

Reputation: 4698

Going forward you can follow these steps (through terminal) so that same issues don't crop up again.

  1. Create a conda environment if it's not already done

    conda create -n py3_env python=3.8

  2. Get into the conda environment

    conda activate py3_env

  3. Install ipykernel

    conda install ipykernel

  4. Link the kernel to this conda env

    ipython kernel install --user --name=py3_env

  5. Deactivate the conda environment

    conda deactivate

Now, when you open jupyter, you can select this kernel from the dropdown menu kernel >> Change kernel. Now, all the packages you've installed in this conda environment would be available in jupyter as well. E.g. you can install nltk in this environment in the following way:

conda activate py3_env
pip install nltk
conda deactivate

Upvotes: 1

Related Questions