0

I am trying to include a package for which i installed using the cmd window and pip. It installed successfully however when i go to use it in Pycharm it returns an error saying the package is not installed. When I try to install it using Pycharm it fails.

Is there any way to get Pycharm to recognize the package that is installed already?

enter image description here

  • 3
    You probably installed the packages in your system python, but you're working with a virtual environment; just use PyCharm package manager to install packages and you'll be fine – crissal Jun 07 '21 at 09:31
  • For me there is also another issue. If you try to add a folder that in the past had a `.idea` folder, but your current project has it's own `.idea` folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the `.idea` folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red. – Charlie Parker Jul 21 '22 at 19:21

2 Answers2

2

PyCharm does not use the same python interpreter as the one you installed package for.
As @crissal said, you can use PyCharm package manager to install packages, or configure it to recognize the one you already have:

  1. In your cmd, type which python and you'll get something like /usr/bin/python (on win it might be different but doesn't matter). That's the path of your default interpeter.
  2. In PyCharm: Preferences -> Project -> Python Interpreter
  3. Choose path if listed, or Show all -> + -> find and select path
  4. Now in top right corner of the window, next to run button, select interpeter dropdown and Edit configuration
  5. Select correct Python interpreter, give it a few moments PyCharm will figure out your nltk dependency

I would strongly suggest using virtual environment for each project, in order not to mix dependencies.

nenadp
  • 798
  • 1
  • 7
  • 15
  • For me there is also another issue. If you try to add a folder that in the past had a `.idea` folder, but your current project has it's own `.idea` folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the `.idea` folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red. – Charlie Parker Jul 21 '22 at 19:21
0

first uninstall nltk then try to install it from the PyCharm command line using the same interpreter.

Sandeep Agrawal
  • 175
  • 1
  • 8
  • For me there is also another issue. If you try to add a folder that in the past had a `.idea` folder, but your current project has it's own `.idea` folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the `.idea` folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red. – Charlie Parker Jul 21 '22 at 19:21