Launch PyMol from Python Interpreter

This section provides a tutorial on how to launch PyMol from a Python interpreter with 'import pymol' and 'pymol.cmd.*()' statements.

If you want to launch PyMol from a Python interpreter, you need to make sure that "pymol" module package files are in Python "import" search path. There are two ways to get this done: the easy way and the hard way.

The Easy Way - Using the PyMol Built-in Python Interpreter - The PyMol installation already includes a built-in Python interpreter. If you use this Python interpreter, "pymol" module package files are automatically included in the "import" search path.

The Hard Way - Using a Standalone Python Interpreter - You have to find the location of "pymol" module package files and add it to the "import" search path manually. You may also run into version compatibility issue too.

With new versions of PyMol, when you call any of the pymol.cmd.*() function for the first time, PyMol will be launched automatically.

Now let's try to use PyMol Built-in Python Interpreter on my macOS system. It is located in the /Applications/ folder.

herong$ /Applications/
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import pymol
>>> Cannot find license file.
 The license files (or license server system network addresses) attempted are
listed below.  Use LM_LICENSE_FILE to use a different license file,
 or contact your software provider for a license file.
Feature:       PYMOL_MAIN
Filename:      /Library/Application Support/Schrodinger/licenses
License path:  /Library/Application Support/Schrodinger/licenses:
FlexNet Licensing error:-1,359.  System Error: 2 "No such file or directory"
For further information, refer to the FlexNet Licensing documentation,
available at "".

>>> pymol.cmd.load('Molecule-Methane.sdf')
 PyMOL not running, entering library mode (experimental)

>>> pymol.cmd.turn('y',45)
>>> pymol.cmd.draw()

As you can see, PyMol was launched by the pymol.cmd.load() call in library mode, not in the GUI mode. I don't see the PyMol viewer window displayed, maybe because of the expired evaluation license.

Running PyMol in library mode is still useful. You can load your molecule structures and change viewing parameters to generate nice looking pictures, or create states and define frames to produce movies.

Table of Contents

 About This Book

 Introduction of Molecules

 Molecule Names and Identifications

 Protein and Amino Acid

 Nucleobase, Nucleoside, Nucleotide, DNA and RNA

 Gene and Chromosome

 Protein Kinase (PK)

 SDF (Structure Data File)

 RDKit: Open-Source Cheminformatics Software

 PyMol Installation

 PyMol GUI and CLI

 PyMol Selections

 PyMol Editing Functions

 PyMol Measurement Functions

 PyMol Movie Functions

PyMol Python Integration

 Run Python Statements from PyMol

 PyMol Python API

Launch PyMol from Python Interpreter

 PyMol Python API Only Functions

 PyMol Object Functions

 ChEMBL Database - European Molecular Biology Laboratory

 PubChem Database - National Library of Medicine

 PDB (Protein Data Bank)

 INSDC (International Nucleotide Sequence Database Collaboration)

 Resources and Tools

 Molecule Related Terminologies


 Full Version in PDF/EPUB