简体   繁体   中英

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?

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. Eg you can install nltk in this environment in the following way:

conda activate py3_env
pip install nltk
conda deactivate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM