Show Python Library Mac
August 2007
- Installing Python
Feb 17, 2013 Python's OS Module. The functions that the OS module provides allows you to interface with the underlying operating system that Python is running on – be that Windows, Mac or Linux. You can find important information about your location or about the process. In this post I will show some of these functions. OS functions. Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials. The Houdini Object Model (HOM) is an application programming interface (API) that lets you get information from and control Houdini using the Python scripting language.HOM replaces the functionality of Houdini’s previous command language, HScript. In Python, the hou package is the top of a hierarchy of modules, functions, and classes that define the HOM. Opening a notebook as a Python file allows you to use all of VS Code's debugging capabilities. You can then save the notebook file and open it again as a notebook in the Notebook Editor, Jupyter, or even upload it to a service like Azure Notebooks. Using either method, Notebook Editor or a Python file.
Introduction
So you've decided to use theGoogle Data Python client library towrite an application using one of the manyGoogle Data services. Excellent choice!My aim with this short tutorial is to quickly get you started in using the client libraryto develop your application.
You probably want to jump in and start creating your application right away.First though, you may need to configureyour development environment and set up the tools you'll need to run the modules includedin the client library. Follow the steps below and you'll be running code in no time.
Installing Python
If you're going to be developing with the Python client library, you'll needa working version of Python 2.2 or higher. Many operating systems come with a versionof Python included, so you may be able to skip the installation step.To see which version of Python you have, run python -V
in acommand line terminal. (Note: the V
is uppercase.)This should result in something like:
If you see version 2.2 or higher, then you can startinstalling dependencies. Otherwise, look below to find installation/upgradeinstructions for your operating system.
Installing Python on Windows
There are quite a few implementations of Python to choose from in Windows, but for purposes of this guide, I'llbe using the .msi installer found on python.org.
- Begin by downloading the installer from the Python download page.
- Run the installer - you can accept all the default settings
- To see if your install is working as expected, open a command prompt and run
python -V
.
Installing Python on Mac OS X
The list of downloads on python.org has .dmg installers for the Mac users out there.Here are the steps to install one of them:
- Navigate to http://www.python.org/download/mac/
- From this page, download the installer for the appropriate version of Mac OS X. Note: The Python installation page forMac OS X 10.3.8 and below is different than newer versions of Mac OS X. To find your OS X version, chooseAbout This Mac from the Apple menu in the top-left corner of your screen.
- After the download finishes, double-click the new disk image file (ex. python-2.5-macosx.dmg) to mount it.If you're running Safari, this has already been done for you.
- Open the mounted image and double-click the installer package inside.
- Follow the installation instructions and read the information and license agreements asthey're presented to you. Again, the default settings will work fine here.
- Verify the installation by opening Terminal.app (in /Applications/Utilities) and running
python -V
.The installation's version should appear.
Installing Python on Linux
To install on Linux and other *nix style operating systems,I prefer to download the source code and compile it.However, you may be able to use your favorite package manager to install Python.(For example, on Ubuntu this can be as easy asrunning sudo apt-get install python
on the command line.) To install from source, follow these steps:
- Download the source tarball from the Python download page.
- Once you've downloaded the package, unpack it using the command line. You can use the following
- Next, you'll need to compile and install the source code for the Python interpreter. In the decompressed directory, run
./configure
to generate a makefile. - Then, run
make
. This will create a working Python executable file in the local directory. If you don't have root permission or you just want to use Python from your home directory, you can stop here. You'll be able to run Python from this directory, so you might want to add it to your PATH environment variable. - I prefer to have Python installed in
/usr/bin/
where most Python scripts look for the interpreter. If you have root access, then runmake install
as root. This will install Python in the default location and it will be usable by everyone on your machine. - Check to see if your install is working as expected by opening a terminal and running
python -V
.
Installing Dependencies
Currently, the only external dependency is an XML library namedElementTree.If you are using Python version 2.5 or higher, you won't need to installElementTree since it comes with the Python package.
To see if ElementTree is already present on your system, do the following:
- Run the Python interpreter. I usually do this by executing
python
on the command line. - Try importing the ElementTree module. If you are using Python 2.5 or higher, enter the following in the interpreter: For older versions, enter:
- If the import fails, then you will need to continue reading this section. If it works, then you can skip to Installing the Google Data library.
- Download a version which is appropriate for your operating system. For example, if you are using Windows, download elementtree-1.2.6-20050316.win32.exe. For other operating systems, I recommend downloading a compressed version.
- If you are using a
.tar.gz
or.zip
version of the library, first unpack, then install it by running./setup.py install
.
Running ./setup.py install
attempts to compile the library and place it in the system directory for your Python modules. If you do not haveroot access, you can install the modules in your home directory or an alternate location by running ./setup.py install --home=~
. This willplace the code in your home directory.
There is another option which avoids installing altogether. Once you decompress the download, you will find a directory named elementtree
. Thisdirectory contains the modules which you will need to import. When you call import from within Python, it looks for a module with the desired name in several places. Thefirst place it looks is in the current directory, so if you are always running your code from one directory, you could just put the elementtree
directorythere. Python will also look at the directories listed in yourPYTHONPATH
environment variable. For instructions on editing yourPYTHONPATH
,see the Appendix at the end of this article.I recommend using ./setup.py install
for elementtree
.
Installing the Google Data Library
Download the Google Data Python library if you haven't done so.Look for the latest version on the Python project's downloads page.
After downloading the library, unpack it using unzip
or tar zxvf
depending on the type of download you chose.
Now you are ready to install the library modules so that they can be imported into Python. There are several ways you can do this:
- If you have the ability to install packages for all users to access, you can run
./setup.py install
from theunpacked archive's main directory. - If you want to install these modules for use in your home directory, you can run
./setup.py install --home=
<your home directory>. In some cases, you want to avoid installing the modules altogether. To do that, modify your
PYTHONPATH
environment variable to includea directory which contains thegdata
andatom
directories for the Google Data Python client library. For instructions on modifying yourPYTHONPATH
,see the Appendix at the end of this article.- One final option that I'll mention, is copying the
gdata
andatom
directories from thesrc
directory into whateverdirectory you are in when you executepython
.Python will look in the current directory when you do an import, but I don't recommend this method unless you are creating something quick and simple.
Once you've installed the Google Data library, you're ready to take the library for a test drive.
Running Tests and Samples
The Google Data Python client library distributions includesome test cases which are used in the development of the library. They can also serve as a quickcheck to make sure that your dependencies and library installation are working. From the top level directory where you've unpacked your copy of the library, try running:
Mac mp3 library manager. If this script runs correctly, you should see output on the command line like this:
If you did not see any errors as the tests execute, then you have probably set up your environment correctly. Congratulations!
Now you can start running something more interesting. The distribution contains a samples
directory which contains code which can providea starting point for writing your application. If you'd like to try out a simple interactive sample, try running ./samples/docs/docs_example.py
.The Google Documents List API sample will prompt you for the email address and password for your Google account. If you have any documents or spreadsheets inGoogle Documents, you can list them by entering 1
for your selected operation. (If you don't have anydocuments or spreadsheets, you'll get a 404 error.)
Writing a 'Hello World' Example
Let's start with a simple example. Here's a short program to print a list of all of the documents in yourGoogle Documents account:
Either save the above code snippet as a file and run it, or paste the code into the Python interpreter to see the Google DataPython client library at work.
Show Python Library Mac Download
Conclusion
Now that you've installed and tested the Google Data Pythonclient library, you're ready to start writing the next great application using:
As you continue to develop your application, you may hit a snag. If so, please check out the list of resources below:
If you happen to think of a great new feature for the library (or by chance find a bug),please enter it in thediscussion group.We're always interested in your feedback!
Happy coding :-)
Appendix: Modifying the PYTHONPATH
When you import a package or module in Python, the interpreter looks for the file in a series of locationsincluding all of the directories listed in the PYTHONPATH
environment variable. I often modify my PYTHONPATH
topoint to modules where I have copied the source code for a library I am using. This prevents the need to install a moduleeach time it is modified because Python will load the module directly from directory which contains the modified source code.
I recommend the PYTHONPATH
approach if you are making changes to the client library code, or if you do not haveadmin rights on your system. By editing the PYTHONPATH
, you can put the required modules anywhere you like.
I modified my PYTHONPATH
on a *nix and Mac OS X system by setting it in my .bashrc
shell configuration file.If you are using the bash shell,you can set the variable by adding the following line to your ~/.bashrc
file.
You can then apply these changes to your current shell session by executing source ~/.bashrc
.
For Windows XP, pull up the Environment Variables for your profile: Control Panel > System Properties > Advanced > Environment Variables. From there, you can either create or edit the PYTHONPATH
variable and add the location of your local library copy.
Show Python Library Mac Torrent
Bob Savage <bobsavage@mac.com>
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 (https://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.
What you get after installing is a number of things:
A
Python3.8
folder in yourApplications
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.html) are good choices, as isTextMate (see https://macromates.com/). Other editors includeGvim (http://macvim-dev.github.io/macvim/) 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.8, you can use either python or pythonw.
4.1.3. Configuration¶
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 fordetails.
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://www.hashcollision.org/hkn/python/idle_intro/index.html.
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 https://pip.pypa.io/.
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 https://pypi.org/project/pyobjc/.
First you have to know that Borland’s object fileformat (OMF) is different from the format used by the Python version you candownload from the Python or ActiveState Web site. Python install libraries on mac. (Python is built withMicrosoft Visual C, which uses COFF as the object file format.) For thisreason you have to convert Python’s library python25.lib into theBorland format.
The standard Python GUI toolkit is tkinter
, based on the cross-platformTk toolkit (https://www.tcl.tk). An Aqua-native version of Tk is bundled with OSX by Apple, and the latest version can be downloaded and installed fromhttps://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 https://www.wxpython.org.
PyQt is another popular cross-platform GUI toolkit that runs natively on MacOS X. More information can be found athttps://riverbankcomputing.com/software/pyqt/intro.
4.5. Distributing Python Applications on the Mac¶
The “Build Applet” tool that is placed in the MacPython 3.6 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.
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.
4.6. Other Resources¶
The MacPython mailing list is an excellent support resource for Python users anddevelopers on the Mac:
Another useful resource is the MacPython wiki: