Installing Python 3 on Mac OS X¶ Mac OS X comes with Python 2.7 out of the box. If you perform a fresh install of Xcode, you will also need to add the commandline tools by running xcode-select-install on the terminal. While OS X comes with a large number of Unix utilities, those familiar with Linux systems will notice one key component. Installing Packages¶. This section covers the basics of how to install Python packages. It’s important to note that the term “package” in this context is being used as a synonym for a distribution (i.e. A bundle of software to be installed), not to refer to the kind of package that you import in your Python source code (i.e. A container of modules).
- Uninstall Python Mac Terminal
- Install Python Library Mac Terminal 3
- Install Python Mac Terminal
- Mac Terminal Install Python Package
In this tutorial, you will learn –
Installing NLTK in Windows
In this part, we will learn that how to make setup NLTK via terminal (Command prompt in windows).
The instruction given below are based on the assumption that you don't have python installed. So, first step is to install python.
Installing Python in Windows:
Step 1) Go to link https://www.python.org/downloads/, and select the latest version for windows.
Note: If you don't want to download the latest version, you can visit the download tab and see all releases.
Step 2) Click on the Downloaded File
Step 3)Select Customize Installation
Step 4) Click NEXT
Step 5) In next screen
- Select the advanced options
- Give a Custom install location. In my case, a folder on C drive is chosen for ease in operation
- Click Install
Step 6) Click Close button once install is done.
Step 7) Copy the path of your Scripts folder.
Step 8) In windows command prompt
- Navigate to the location of the pip folder
- Enter command to install NLTK
- Installation should be done successfully
NOTE: For Python2 use the commandpip2 install nltk
Step 9) In Windows Start Menu, search and open PythonShell
Step 10) You can verify whether the installation is accurate supplying the below command
If you see no error, Installation is complete.
Installing NLTK in Mac/Linux
Installing NLTK in Mac/Unix requires python package manager pip to install nltk. If pip is not installed, please follow the below instructions to complete the process
Step1) Update the package index by typing the below command
Step2) Installing pip for Python 3:
You can also install pip using easy_install.
Now easy_install is installed. Run the below command to install pip
Step3)Use following command to install NLTK
Installing NLTK through Anaconda
Step1) Please install anaconda (which can also be used to install different packages) by visiting https://www.anaconda.com/download/ and select which version of python you need to install for anaconda.
Note: Refer to this tutorial for detailed steps to install anaconda
Step 2)In the Anaconda prompt,
- Enter command
- Review the package upgrade, downgrade, install information and enter yes
- NLTK is downloaded and installed
NLTK module has many datasets available that you need to download to use. More technically it is called corpus. Some of the examples are stopwords, gutenberg, framenet_v15, large_grammarsand so on.
How to Download all packages of NLTK
Step 1)Run the Python interpreter in Windows or Linux
- Enter the commands
- NLTK Downloaded Window Opens. Click the Download Button to download the dataset. This process will take time, based on your internet connection
NOTE: You can change the download location by Clicking File> Change Download Directory
Step 3) To test the installed data use the following code
['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', ..]
Running the NLP Script
We are going to discuss how NLP script will be executed on our local PC. There are many libraries for Natural Language Processing present in the market. So choosing a library depends on fitting your requirements. Here is the list of NLP libraries.
How to Run NLTK Script
Step1) In your favorite code editor, copy the code and save the file as 'NLTKsample.py '
- In this program, the objective was to remove all type of punctuations from given text. We imported 'RegexpTokenizer' which is a module of NLTK. It removes all the expression, symbol, character, numeric or any things whatever you want.
- You just have passed the regular Expression to the 'RegexpTokenizer' module.
- Further, we tokenized the word using 'tokenize' module. The output is stored in the 'filterdText' variable.
- And printed them using 'print().'
Step2)In the command prompt
- Navigate to the location where you have saved the file
- Run the command Python NLTKsample.py
This will show output as :
['Hello', 'Guru99', 'You', 'have', 'build', 'a', 'very', 'good', 'site', 'and', 'I', 'love', 'visiting', 'your', 'site']
|Author:||Bob Savage <firstname.lastname@example.org>|
Python on a Macintosh running Mac OS X is in principle very similar to Python onany other Unix platform, but there are a number of additional features such asthe IDE and the Package Manager that are worth pointing out.
4.1. Getting and Installing MacPython¶
Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple. If you wish, youare invited to install the most recent version of Python 3 from the Pythonwebsite (http://www.python.org). A current “universal binary” build of Python,which runs natively on the Mac’s new Intel and legacy PPC CPU’s, is availablethere. Hidden folder virus.
What you get after installing is a number of things:
- A MacPython3.3 folder in your Applications folder. In hereyou find IDLE, the development environment that is a standard part of officialPython distributions; PythonLauncher, which handles double-clicking Pythonscripts from the Finder; and the “Build Applet” tool, which allows you topackage Python scripts as standalone applications on your system.
- A framework /Library/Frameworks/Python.framework, which includes thePython executable and libraries. The installer adds this location to your shellpath. To uninstall MacPython, you can simply remove these three things. Asymlink to the Python executable is placed in /usr/local/bin/.
The Apple-provided build of Python is installed in/System/Library/Frameworks/Python.framework and /usr/bin/python,respectively. You should never modify or delete these, as they areApple-controlled and are used by Apple- or third-party software. Remember thatif you choose to install a newer Python version from python.org, you will havetwo different but functional Python installations on your computer, so it willbe important that your paths and usages are consistent with what you want to do.
IDLE includes a help menu that allows you to access Python documentation. If youare completely new to Python you should start reading the tutorial introductionin that document.
If you are familiar with Python on other Unix platforms you should read thesection on running Python scripts from the Unix shell.
4.1.1. How to run a Python script¶
Your best way to get started with Python on Mac OS X is through the IDLEintegrated development environment, see section The IDE and use the Help menuwhen the IDE is running.
If you want to run Python scripts from the Terminal window command line or fromthe Finder you first need an editor to create your script. Mac OS X comes with anumber of standard Unix command line editors, vim andemacs among them. If you want a more Mac-like editor,BBEdit or TextWrangler from Bare Bones Software (seehttp://www.barebones.com/products/bbedit/index.shtml) are good choices, as isTextMate (see http://macromates.com/). Other editors includeGvim (http://macvim.org) and Aquamacs(http://aquamacs.org/).
To run your script from the Terminal window you must make sure that/usr/local/bin is in your shell search path.
To run your script from the Finder you have two options:
- Drag it to PythonLauncher
- Select PythonLauncher as the default application to open yourscript (or any .py script) through the finder Info window and double-click it.PythonLauncher has various preferences to control how your script islaunched. Option-dragging allows you to change these for one invocation, or useits Preferences menu to change things globally.
4.1.2. Running scripts with a GUI¶
With older versions of Python, there is one Mac OS X quirk that you need to beaware of: programs that talk to the Aqua window manager (in other words,anything that has a GUI) need to be run in a special way. Use pythonwinstead of python to start such scripts.
With Python 3.3, you can use either python or pythonw.
Python on OS X honors all standard Unix environment variables such asPYTHONPATH, but setting these variables for programs started from theFinder is non-standard as the Finder does not read your .profile or.cshrc at startup. You need to create a file ~/.MacOSX/environment.plist. See Apple’s Technical Document QA1067 for details.
For more information on installation Python packages in MacPython, see sectionInstalling Additional Python Packages.
4.2. The IDE¶
MacPython ships with the standard IDLE development environment. A goodintroduction to using IDLE can be found athttp://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html.
Uninstall Python Mac Terminal
4.3. Installing Additional Python Packages¶
There are several methods to install additional Python packages:
- Packages can be installed via the standard Python distutils mode (pythonsetup.pyinstall).
- Many packages can also be installed via the setuptools extensionor pip wrapper, see http://www.pip-installer.org/.
4.4. GUI Programming on the Mac¶
There are several options for building GUI applications on the Mac with Python.
PyObjC is a Python binding to Apple’s Objective-C/Cocoa framework, which isthe foundation of most modern Mac development. Information on PyObjC isavailable from http://pyobjc.sourceforge.net.
The standard Python GUI toolkit is tkinter, based on the cross-platformTk toolkit (http://www.tcl.tk). An Aqua-native version of Tk is bundled with OSX by Apple, and the latest version can be downloaded and installed fromhttp://www.activestate.com; it can also be built from source.
wxPython is another popular cross-platform GUI toolkit that runs natively onMac OS X. Packages and documentation are available from http://www.wxpython.org.
PyQt is another popular cross-platform GUI toolkit that runs natively on MacOS X. More information can be found athttp://www.riverbankcomputing.co.uk/software/pyqt/intro.
4.5. Distributing Python Applications on the Mac¶
The “Build Applet” tool that is placed in the MacPython 3.3 folder is fine forpackaging small Python scripts on your own machine to run as a standard Macapplication. This tool, however, is not robust enough to distribute Pythonapplications to other users.
How to run a Python scriptYour best way to get started with Python on Mac OS X is through the IDLEintegrated development environment, see section and use the Help menuwhen the IDE is running.If you want to run Python scripts from the Terminal window command line or fromthe Finder you first need an editor to create your script. Open mac library. If youare completely new to Python you should start reading the tutorial introductionin that document.If you are familiar with Python on other Unix platforms you should read thesection on running Python scripts from the Unix shell. Remember thatif you choose to install a newer Python version from python.org, you will havetwo different but functional Python installations on your computer, so it willbe important that your paths and usages are consistent with what you want to do.IDLE includes a help menu that allows you to access Python documentation. Mac OS X comes with anumber of standard Unix command line editors, vim andemacs among them. You should never modify or delete these, as they areApple-controlled and are used by Apple- or third-party software.
The standard tool for deploying standalone Python applications on the Mac ispy2app. More information on installing and using py2app can be foundat http://undefined.org/python/#py2app.
Install Python Library Mac Terminal 3
4.6. Other Resources¶
Install Python Mac Terminal
The MacPython mailing list is an excellent support resource for Python users anddevelopers on the Mac:
Mac Terminal Install Python Package
Another useful resource is the MacPython wiki: