risch: recognize Derivatives as components (#1012)
[sympy.git] / bin / isympy
blob7cc2a9013b120aa99a46f1dedc6e927725758d79
1 #!/usr/bin/python
3 """Python shell for SymPy.
5 This is just a normal Python shell (IPython shell if you have the
6 IPython package installed), that executes the following commands
7 for the user:
9 >>> from __future__ import division
10 >>> from sympy import *
11 >>> x, y, z = symbols("xyz")
12 >>> k, m, n = symbols("kmn", integer=True)
13 >>> f, g, h = map(Function, 'fgh')
15 So starting 'isympy' is equivalent to starting Python (or IPython)
16 and executing the above commands by hand. It is intended for easy
17 and quick experimentation with SymPy.
19 COMMAND LINE OPTIONS
20 --------------------
22 -c CONSOLE, --console=CONSOLE
24 Use the specified Python or IPython shell as console backend instead
25 of the default one (IPython if present or Python otherwise), e.g.:
27 isympy -c python
29 -p PRETTY, --pretty PRETTY
31 Setup pretty printing in SymPy. By default the most pretty, Unicode
32 printing is enabled. User can use less pretty ASCII printing instead
33 or no pretty printing at all, e.g.:
35 -q, --quiet
37 Print only Python's and SymPy's versions to stdout at startup.
39 -- IPython's options
41 Additionally you can pass command line options directly to IPython
42 interpreter (standard Python shell is not supported). However you
43 need to add '--' separator between two types of options. To run
44 SymPy without startup banner and colors, for example, issue:
46 isympy -q -- -colors NoColor
48 """
50 import os, sys
52 # hook in-tree SymPy into Python path, if possible
54 isympy_dir = os.path.dirname(__file__) # bin/isympy
55 sympy_top = os.path.split(isympy_dir)[0] # ../
56 sympy_dir = os.path.join(sympy_top, 'sympy') # ../sympy/
58 if os.path.isdir(sympy_dir):
59 sys.path.insert(0, sympy_top)
61 # some longer messages
63 long_message = """\
64 These commands were executed:
65 >>> from __future__ import division
66 >>> from sympy import *
67 >>> x, y, z = symbols('xyz')
68 >>> k, m, n = symbols('kmn', integer=True)
69 >>> f, g, h = map(Function, 'fgh')
71 Documentation can be found at http://sympy.org/
72 """
74 no_ipython = """\
75 Couldn't locate IPython. Having IPython installed is greatly recommended.
76 See http://ipython.scipy.org for more details. If you use Debian/Ubuntu,
77 just install the 'ipython' package and start isympy again.
78 """
80 from sympy.interactive import init_session
82 def main():
83 from sympy import __version__ as sympy_version
84 py_version = "%d.%d.%d" % sys.version_info[:3]
86 from optparse import OptionParser
88 usage = 'usage: isympy [options] -- [ipython options]'
89 parser = OptionParser(usage, version=sympy_version)
91 parser.add_option(
92 '-c', '--console',
93 dest='console',
94 action='store',
95 default=None,
96 help='select type of interactive session: IPython | Python')
98 parser.add_option(
99 '-p', '--pretty',
100 dest='pretty',
101 action='store',
102 default="any",
103 help='setup pretty printing: Unicode | ASCII | any | no')
105 parser.add_option(
106 '-q', '--quiet',
107 dest='quiet',
108 action='store_true',
109 default=False,
110 help='print only version information at startup')
112 (options, ipy_args) = parser.parse_args()
114 session = options.console
116 if session is not None:
117 session = session.lower()
119 args = {
120 'argv' : ipy_args,
121 'pretty' : True,
122 'use_unicode' : None,
125 pretty = options.pretty.lower()
127 if pretty != 'any':
128 if pretty == 'unicode':
129 args['use_unicode'] = True
130 else:
131 args['use_unicode'] = False
133 if pretty != 'ascii':
134 if pretty == 'no':
135 args['pretty'] = False
136 else:
137 raise ValueError("Unknown pretty" \
138 " printing setup: " + options.pretty)
140 if not options.quiet:
141 args['message'] = long_message
143 try:
144 init_session(session, **args)
145 except ValueError:
146 try:
147 init_session('ipython', **args)
148 except ImportError:
149 print no_ipython
150 init_session('python', **args)
152 if __name__ == "__main__":
153 main()