問題描述
在 Ubuntu 中與 EPD python 一起安裝 NLTK (Installing NLTK alongside EPD python in Ubuntu)
I am a recent convert from Matlab/ Windows to Python/ Ubuntu. I have installed EPD python which is a python distribution that includes most scientific packages, I am super happy so far. Next, I needed to install NLTK to do some text analytics and followed the instructions on the nltk webpage. Problem is that all the packages (pyyaml,nltk etc) are getting installed into
/usr/local/lib/python2.7
However, I already changed my .bashrc (as specifed in post‑installations instructions of EPD) and added the following line at the end of it.
export PATH=/home/myname/epd/bin:$PATH
and sys.path from my python shell returns
['',
'/home/myname/epd/bin',
'/home/myname/epd/lib/python2.7/site‑packages/pandas‑0.10.0‑py2.7‑ linux‑i686.egg',
'/home/myname/epd/lib/python27.zip',
'/home/myname/epd/lib/python2.7',
'/home/myname/epd/lib/python2.7/plat‑linux2',
'/home/myname/epd/lib/python2.7/lib‑tk',
'/home/myname/epd/lib/python2.7/lib‑old',
'/home/myname/epd/lib/python2.7/lib‑dynload',
'/home/myname/epd/lib/python2.7/site‑packages',
'/home/myname/epd/lib/python2.7/site‑packages/PIL',
'/home/myname/epd/lib/python2.7/site‑packages/IPython/extensions']
Any help regarding how to make new python packages install into the right path is much appreciated. If you have time, please do elaborate on why this is happening and what I am doing wrong. Thanks a ton for you time!
‑‑‑‑‑
參考解法
方法 1:
You have two good choices for setting up your python environment in ubuntu:
Use the ubuntu packages, like Thorsten suggests.
Use the pip package manager in a virtualenv. This way you can set up multiple environments and hop from one to the other. A virtualenv can be configured to also include the system‑wide ubuntu packages.
nltk exists as a pip package: http://pypi.python.org/pypi/nltk/2.0.4
pip has some trouble on ubuntu when linking to c libraries, since ubuntu places them in a place where the setup scripts do not look. Make sure to also install the ‑dev version of the dependency packages, since they contain the header files that pip needs, and copy or link the libraries from /usr/lib/your linux architecture/lib/ to /usr/local/lib so that pip may find them.
方法 2:
I recently installed NLTK and PyYAML because I'm working through "Natural Language Processing with Python". I was pleasantly surprised to find that both are available through the EPD package manager enpkg (although NLTK isn't listed on the Enthought site as being available).
$ enpkg ‑s pyyaml
Name Versions Note
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
PyYAML 3.9‑2
3.10‑1
$ enpkg ‑s nltk
Name Versions Note
‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑
nltk 2.0.1rc1‑1
2.0.1rc1‑2
2.0.1‑1
You can install both using:
$ enpkg pyyaml
$ enpkg nltk
and you're good to go!
方法 3:
For scientific python modules in NLTK, normally scipy
would have suffice basic scientific functions and numpy
would have covered the statistics. The NLTK installation site strongly recommends pip
too. http://nltk.org/install.html
Open Finder>Applications>Utilities>Terminal and type python ‑V to find out what version of Python is installed
Install Setuptools: Download the corresponding version of Setuptools from http://pypi.python.org/pypi/setuptools (scroll to the bottom, and pick the filename that contains the right version number and which has the extension .egg). Install it by typing sudo sh Downloads/setuptools‑...egg, giving the location of the downloaded file.
Install Pip: run sudo easy_install pip
Install Numpy (optional): run sudo pip install ‑U numpy
Install PyYAML and NLTK: run sudo pip install ‑U pyyaml nltk
Test installation: run python then type import nltk
(by chezobore、flup、PythonJin、alvas)