Reputation: 143
I'm getting an error while executing a function from a module in PyCharm 5:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/apple/Dropbox/PycharmProjects/work/2-chapter.py
...
...
AttributeError: 'module' object has no attribute 'corpus'
That is supposed to be nltk.corpus.
After having played with Project Structure (in Preferences) and adding there both /usr/local/lib/python2.7/site-packages and /Library/Python/2.7/site-packages paths, nothing still works out.
I am wondering whether I need to add this path as well /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 ?
The problem is I don't have it. I only have path ...Python.framework/Versions/3.5, although I have already installed python 2.7 as well and the interpreter uses python 2.7.5.
The PYTHONPATH is:
$ echo $PYTHONPATH
:/usr/local/lib/python2.7/site-packages
I also tried adding
import sys
sys.path.append("/usr/local/lib/python2.7/site-packages")
to the module I'm talking about, it also didn't work.
Upvotes: 4
Views: 3186
Reputation: 2721
I see a few issues with your current setup:
Project structure pane is for defining your current project's preferences (which folders won't be indexed (excluded), which are to be added to python path (sources)). Based on screenshot, I assume that your project files are in /Users/apple/Dropbox/PycharmProjects/work
folder. That is your "content root"
ntlk is a python package. You can check whether it has been installed on Project > Project Interpreter pane. If it is installed and you're using right interpreter for your project, it will be already in pythonpath, hence no additional actions required. Otherwise you should either press the plus button and install it via PyCharm, or use sudo pip install nltk
Upvotes: 1
Reputation: 333
PYTHONPATH is set in "Project Interpreter" section. There you can set your Project Interpreter from any of your locals Python versions or from virtualenv versions.
If you are still experiencing module problems, it could be because that module is not installed
Upvotes: 2