forked from python4astronomers/python4astronomers.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackages.html
More file actions
809 lines (765 loc) · 37.5 KB
/
Copy pathpackages.html
File metadata and controls
809 lines (765 loc) · 37.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modules, Packages, and all that — Python4Astronomers 1.1 documentation</title>
<link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="Python4Astronomers 1.1 documentation" href="../index.html" />
<link rel="up" title="Python Installation and Understanding Packages" href="installation.html" />
<link rel="next" title="Core packages for analysis: IPython, NumPy, and SciPy" href="../core/core.html" />
<link rel="prev" title="Installing Scientific Python" href="python_install.html" />
<script type="text/javascript">
$(document).ready(function(){
$(".flip0").click(function(){
$(".panel0").slideToggle("normal");
});
$(".flip1").click(function(){
$(".panel1").slideToggle("normal");
});
$(".flip2").click(function(){
$(".panel2").slideToggle("normal");
});
$(".flip3").click(function(){
$(".panel3").slideToggle("normal");
});
$(".flip4").click(function(){
$(".panel4").slideToggle("normal");
});
$(".flip5").click(function(){
$(".panel5").slideToggle("normal");
});
$(".flip6").click(function(){
$(".panel6").slideToggle("normal");
});
$(".flip7").click(function(){
$(".panel7").slideToggle("normal");
});
$(".flip8").click(function(){
$(".panel8").slideToggle("normal");
});
$(".flip9").click(function(){
$(".panel9").slideToggle("normal");
});
});
</script>
<style type="text/css">
div.panel0,p.flip0
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip0
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel0
{
display:none;
}
div.panel1,p.flip1
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip1
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel1
{
display:none;
}
div.panel2,p.flip2
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip2
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel2
{
display:none;
}
div.panel3,p.flip3
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip3
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel3
{
display:none;
}
div.panel4,p.flip4
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip4
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel4
{
display:none;
}
div.panel5,p.flip5
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip5
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel5
{
display:none;
}
div.panel6,p.flip6
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip6
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel6
{
display:none;
}
div.panel7,p.flip7
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip7
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel7
{
display:none;
}
div.panel8,p.flip8
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip8
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel8
{
display:none;
}
div.panel9,p.flip9
{
font-size: 0.9em;
margin: 0;
padding: 0.1em 0 0.1em 0.5em;
border-bottom: 1px solid #86989B;
}
p.flip9
{
color: white;
font-weight: bold;
background-color: #AFC1C4;
}
div.panel9
{
display:none;
}
</style>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18709417-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../core/core.html" title="Core packages for analysis: IPython, NumPy, and SciPy"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="python_install.html" title="Installing Scientific Python"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">Python4Astronomers 1.1 documentation</a> »</li>
<li><a href="installation.html" accesskey="U">Python Installation and Understanding Packages</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Modules, Packages, and all that</a><ul>
<li><a class="reference internal" href="#finding-and-installing-other-packages">Finding and installing other packages</a></li>
<li><a class="reference internal" href="#where-does-python-look-for-modules">Where does Python look for modules?</a></li>
<li><a class="reference internal" href="#multiple-pythons-on-your-computer">Multiple Pythons on your computer</a></li>
<li><a class="reference internal" href="#virtualenv">Virtualenv</a></li>
<li><a class="reference internal" href="#final-exercises">Final exercises</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="python_install.html"
title="previous chapter">Installing Scientific Python</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="../core/core.html"
title="next chapter">Core packages for analysis: IPython, NumPy, and SciPy</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/installation/packages.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="modules-packages-and-all-that">
<h1>Modules, Packages, and all that<a class="headerlink" href="#modules-packages-and-all-that" title="Permalink to this headline">¶</a></h1>
<p>One of the key features of Python is that the actual core language is fairly
small. This is an intentional design feature to maintain simplicity. Much of
the powerful functionality comes through external modules and packages.</p>
<p>The main work of installation so far has been to supplement the core Python
with useful modules for science analysis.</p>
<p><strong>Module</strong></p>
<p>A <a class="reference external" href="http://docs.python.org/tutorial/modules.html">module</a> is simply a file
containing Python definitions, functions, and statements. Putting code into
modules is useful because of the ability to <a class="reference external" href="http://docs.python.org/reference/simple_stmts.html#import">import</a> the module
functionality into your script or IPython session, for instance:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">atpy</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">atpy</span><span class="o">.</span><span class="n">Table</span><span class="p">(</span><span class="s">'my_table.fits'</span><span class="p">)</span>
</pre></div>
</div>
<p>You’ll see <tt class="docutils literal"><span class="pre">import</span></tt> in virtually every Python script and soon it will be
second nature.</p>
<dl class="docutils">
<dt><em>Question</em>:</dt>
<dd>Importing modules and putting the module name in front is such a bother,
why do I need to do this?</dd>
<dt><em>Answer</em>:</dt>
<dd>It keeps everything modular and separate. For instance many modules have a
<tt class="docutils literal"><span class="pre">read()</span></tt> function since this is a common thing to do. Without using the
<tt class="docutils literal"><span class="pre"><module>.<function>(...)</span></tt> syntax there would be no way to know which one
to call.</dd>
</dl>
<div class="admonition tip">
<p class="first admonition-title">Tip</p>
<p>Sometimes it is convenient to make an end-run around the <tt class="docutils literal"><span class="pre"><module>.</span></tt>
prefixing. For instance when you run <tt class="docutils literal"><span class="pre">ipython</span> <span class="pre">--pylab</span></tt> the interpreter
does some startup processing so that a number of functions
from the <a class="reference external" href="http://numpy.scipy.org/">numpy</a> and <a class="reference external" href="http://matplotlib.sourceforge.net/">matplotlib</a> modules are available <em>without</em>
using the prefix.</p>
<p>Python allows this with this syntax:</p>
<div class="highlight-python"><pre>from <module> import *</pre>
</div>
<p>That means to import every function and definition from the module into the
current namespace (in other words make them available without prefixing).
For instance you could do:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">atpy</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">'my_table.fits'</span><span class="p">)</span>
</pre></div>
</div>
<p class="last">A general rule of thumb is that <tt class="docutils literal"><span class="pre">from</span> <span class="pre"><module></span> <span class="pre">import</span> <span class="pre">*</span></tt> is OK for
interactive analysis within IPython but you should avoid using it within
scripts.</p>
</div>
<p><strong>Package</strong></p>
<p>A <a class="reference external" href="http://docs.python.org/tutorial/modules.html#packages">package</a> is just a
way of collecting related modules together within a single tree-like
hierarchy. Very complex packages like <a class="reference external" href="http://numpy.scipy.org/">NumPy</a> or <a class="reference external" href="http://scipy.org/">SciPy</a> have hundreds of
individual modules so putting them into a directory-like structure keeps things
organized and avoids name collisions. For example here is a partial list
of sub-packages available within <a class="reference external" href="http://scipy.org/">SciPy</a></p>
<table border="1" class="docutils">
<colgroup>
<col width="39%" />
<col width="61%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>scipy.fftpack</td>
<td>Discrete Fourier Transform algorithms</td>
</tr>
<tr class="row-even"><td>scipy.stats</td>
<td>Statistical Functions</td>
</tr>
<tr class="row-odd"><td>scipy.lib</td>
<td>Python wrappers to external libraries</td>
</tr>
<tr class="row-even"><td>scipy.lib.blas</td>
<td>Wrappers to BLAS library</td>
</tr>
<tr class="row-odd"><td>scipy.lib.lapack</td>
<td>Wrappers to LAPACK library</td>
</tr>
<tr class="row-even"><td>scipy.integrate</td>
<td>Integration routines</td>
</tr>
<tr class="row-odd"><td>scipy.linalg</td>
<td>Linear algebra routines</td>
</tr>
<tr class="row-even"><td>scipy.sparse.linalg</td>
<td>Sparse Linear Algebra</td>
</tr>
<tr class="row-odd"><td>scipy.sparse.linalg.eigen</td>
<td>Sparse Eigenvalue Solvers</td>
</tr>
<tr class="row-even"><td>scipy.sparse.linalg.eigen.arpack</td>
<td>Eigenvalue solver using iterative methods.</td>
</tr>
</tbody>
</table>
<div class="admonition-exercise-import-a-package-module-and-learn-about-it admonition">
<p class="first admonition-title">Exercise: Import a package module and learn about it</p>
<p class="last">Import the Linear algebra module from the SciPy package and find out what
functions it provides.</p>
</div>
<div class="section" id="finding-and-installing-other-packages">
<h2>Finding and installing other packages<a class="headerlink" href="#finding-and-installing-other-packages" title="Permalink to this headline">¶</a></h2>
<p>If you’ve gotten this far you have a working scientific Python environment that
has <em>most</em> of what you will ever need. Nevertheless it is almost certain that
you will eventually find a need that is not met within your current
installation. Here we learn <strong>where</strong> to find other useful packages and
<strong>how</strong> to install them.</p>
<div class="section" id="package-resources">
<h3>Package resources<a class="headerlink" href="#package-resources" title="Permalink to this headline">¶</a></h3>
<div class="sidebar">
<p class="first sidebar-title">Good vs. bad resources</p>
<p>When you find some package on the web, look for a few things:</p>
<blockquote class="last">
<div><ul class="simple">
<li>Good modern-looking documentation with examples</li>
<li>Installs easily without lots of dependencies (or has detailed
installation instructions)</li>
<li>Actively developed</li>
</ul>
</div></blockquote>
</div>
<div class="section" id="google">
<h4>Google<a class="headerlink" href="#google" title="Permalink to this headline">¶</a></h4>
<p>Google “python blah blah” or “python astronomy blah blah”</p>
</div>
<div class="section" id="resource-lists">
<h4>Resource lists<a class="headerlink" href="#resource-lists" title="Permalink to this headline">¶</a></h4>
<p>There are a number of sites specifically devoted to Python for astronomy with
organized lists of useful resources and packages.</p>
<blockquote>
<div><ul class="simple">
<li><a class="reference external" href="http://www.astropython.org/resources">Astropython.org resources</a></li>
<li><a class="reference external" href="http://oneau.wordpress.com/2010/10/02/python-for-astronomy/">Comfort at 1 AU</a></li>
<li><a class="reference external" href="http://www.astro.washington.edu/users/rowen/AstroPy.html">Astronomical Python</a></li>
</ul>
</div></blockquote>
</div>
<div class="section" id="pypi">
<h4>PyPI<a class="headerlink" href="#pypi" title="Permalink to this headline">¶</a></h4>
<p>The <a class="reference external" href="http://pypi.python.org/pypi">Python Package Index</a> is the main
repository for 3rd party Python packages (about 14000 packages and growing).
An increasing number of <a class="reference external" href="http://pypi.python.org/pypi?:action=browse&show=all&c=385&c=387">astronomy related packages</a>
are available on PyPI, but this list misses a lot of available options.</p>
<p>The advantage of being on PyPI is the ease of installation using
<tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre"><package_name></span></tt>.</p>
<div class="admonition-exercise-find-packages-for-coordinate-manipulations admonition">
<p class="first admonition-title">Exercise: Find packages for coordinate manipulations</p>
<p>Find one or more Python packages that will transform coordinates from Galactic to FK5 ecliptic.</p>
<p class="last"><em>Hint</em>: tags are helpful at astropython.org and don’t forget the “next” button at
the bottom.</p>
</div>
</div>
</div>
<div class="section" id="package-installation">
<h3>Package installation<a class="headerlink" href="#package-installation" title="Permalink to this headline">¶</a></h3>
<p>There are two standard methods for installing a package.</p>
<p><strong>pip install</strong></p>
<p>The <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span></tt> script is available within our scientific Python
installation and is very easy to use (when it works). During the installation
process you already saw many examples of <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span></tt> in action. Features include:</p>
<blockquote>
<div><ul class="simple">
<li>If supplied with a package name then it will query the PyPI site to find out about
that package. Assuming the package is there then <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span></tt> will
automatically download and install the package.</li>
<li>Will accept a local tar file (assuming it contains an installable Python package) or a URL
pointing to a tar file.</li>
<li>Can install in the user package area via <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre"><package</span> <span class="pre">or</span> <span class="pre">URL></span>
<span class="pre">--user</span></tt> (see discussion further down)</li>
</ul>
</div></blockquote>
<p><strong>python setup.py install</strong></p>
<p>Some packages may fail to install via <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span></tt>. Most often there will
be some obvious (or not) error message about compilation or missing
dependency. In this case the likely next step is to download the installation tar
file and untar it. Go into the package directory and look for files like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">INSTALL</span>
<span class="n">README</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">setup</span><span class="o">.</span><span class="n">cfg</span>
</pre></div>
</div>
<p>If there is an INSTALL or README file then hopefully you will find useful
installation instructions. Most well-behaved python packages do the
installation via a standard <tt class="docutils literal"><span class="pre">setup.py</span></tt> script. This is used as follows:</p>
<div class="highlight-python"><pre>python setup.py --help # get options
python setup.py install # install in the python area (root / admin req'd)
python setup.py install --user # install to user's package area</pre>
</div>
<p>More information is available in the <a class="reference external" href="http://docs.python.org/install/index.html">Installing Python Modules</a> page.</p>
</div>
<div class="section" id="where-do-packages-get-installed">
<h3>Where do packages get installed?<a class="headerlink" href="#where-do-packages-get-installed" title="Permalink to this headline">¶</a></h3>
<p>An important option in the installation process is where to put the package
files. We’ve seen the <tt class="docutils literal"><span class="pre">--user</span></tt> option in <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span></tt> and <tt class="docutils literal"><span class="pre">python</span>
<span class="pre">setup.py</span> <span class="pre">install</span></tt>. What’s up with that? In general, if you don’t have to you
should not use <tt class="docutils literal"><span class="pre">--user</span></tt>, but see the discussion in <a class="reference internal" href="#multiple-pythons-on-your-computer">Multiple Pythons on
your computer</a> for a reason you might.</p>
<div class="section" id="with-user">
<h4>WITH <tt class="docutils literal"><span class="pre">--user</span></tt><a class="headerlink" href="#with-user" title="Permalink to this headline">¶</a></h4>
<p>Packages get installed in a local user-owned directory when you do something
like either of the following:</p>
<div class="highlight-python"><pre>pip install --user asciitable
python setup.py install --user</pre>
</div>
<p>This puts the packages into:</p>
<table border="1" class="docutils">
<colgroup>
<col width="13%" />
<col width="87%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>Mac</td>
<td>~/Library/Python/2.x/lib/python/site-packages</td>
</tr>
<tr class="row-even"><td>Linux</td>
<td>~/.local/lib/python-2.x/site-packages</td>
</tr>
<tr class="row-odd"><td>Windows</td>
<td>%APPDATA%/Python/Python2x/site-packages</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">On Mac if you did not use the EPD Python Framework then you may see user
packages within <tt class="docutils literal"><span class="pre">~/.local/lib</span></tt> as for linux. This depends on whether Python
is installed as a MacOS Framework or not.</p>
</div>
</div>
<div class="section" id="without-user">
<h4>WITHOUT <tt class="docutils literal"><span class="pre">--user</span></tt><a class="headerlink" href="#without-user" title="Permalink to this headline">¶</a></h4>
<p>This option may require root or admin privilege because the package will be
installed in the system area instead of your own local directories.
<em>For most astronomers running on a single-user machine this is a good option.</em></p>
<p>Installing this way has the benefit of making the package available for all users of the
Python installation, but has the downside that it is a bit more difficult to back out changes if required.</p>
</div>
<div class="section" id="how-do-i-find-a-package-once-installed">
<h4>How do I find a package once installed?<a class="headerlink" href="#how-do-i-find-a-package-once-installed" title="Permalink to this headline">¶</a></h4>
<p>Finding the file associated with a package or module is simple, just use the <tt class="docutils literal"><span class="pre">help</span></tt>
command in IPython:</p>
<div class="highlight-python"><pre>import scipy
help scipy</pre>
</div>
<p>This gives something like:</p>
<div class="highlight-python"><pre>NAME
scipy
FILE
/usr/local/lib/python2.6/site-packages/scipy/__init__.py
DESCRIPTION
SciPy: A scientific computing package for Python
================================================
Documentation is available in the docstrings and
online at http://docs.scipy.org.
...</pre>
</div>
</div>
</div>
<div class="section" id="uninstalling-packages">
<h3>Uninstalling packages<a class="headerlink" href="#uninstalling-packages" title="Permalink to this headline">¶</a></h3>
<p>There is no simple and fully consistent way to do this. The Python
community is working on this one. In most simple cases, however, you can just
delete the module file or directory that is revealed by the technique shown above.</p>
</div>
<div class="section" id="getting-help-on-package-installation">
<h3>Getting help on package installation<a class="headerlink" href="#getting-help-on-package-installation" title="Permalink to this headline">¶</a></h3>
<p>If you attempt to install a package but it does not work, your basic options are:</p>
<blockquote>
<div><ul>
<li><p class="first">Dig in your heels and start reading the error messages to see why it is
unhappy. Often when you find a specific message it’s time to start
googling by pasting in the relevant parts of the message.</p>
</li>
<li><p class="first">Send an email to the <a class="reference external" href="http://mail.scipy.org/mailman/listinfo/astropy">AstroPy</a> mailing list
<a class="reference external" href="mailto:astropy%40scipy.org">astropy<span>@</span>scipy<span>.</span>org</a>. Include:</p>
<blockquote>
<div><ul class="simple">
<li>Package you are trying to install</li>
<li>URL for downloading the package tar file</li>
<li>Your platform (machine architecture and exact OS version)</li>
<li>Exactly what you typed</li>
<li>Entire output from the <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt> process</li>
</ul>
</div></blockquote>
<p>Do NOT just write and say “I tried to install BLAH and it failed, can
someone help?”</p>
</li>
</ul>
</div></blockquote>
</div>
</div>
<div class="section" id="where-does-python-look-for-modules">
<h2>Where does Python look for modules?<a class="headerlink" href="#where-does-python-look-for-modules" title="Permalink to this headline">¶</a></h2>
<p>The official reference on <a class="reference external" href="http://docs.python.org/install/index.html#modifying-python-s-search-path">Modifying Python’s Search Path</a>
gives all the details. In summary:</p>
<p>When the Python interpreter executes an import statement, it looks for modules
on a search path. A default value for the path is configured into the Python
binary when the interpreter is built. You can determine the path by importing
the <a class="reference external" href="http://docs.python.org/library/sys.html#module-sys">sys</a> module and
printing the value of <tt class="docutils literal"><span class="pre">sys.path</span></tt>:</p>
<div class="highlight-python"><pre>$ python
Python 2.2 (#11, Oct 3 2002, 13:31:27)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
'/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',
'/usr/local/lib/python2.3/site-packages']
>>></pre>
</div>
<p>Within a script it is possible to adjust the search path by modify <tt class="docutils literal"><span class="pre">sys.path</span></tt>
which is just a Python list. Generally speaking you will want to put your path
at the front of the list using insert:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sys</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s">'/my/path/python/packages'</span><span class="p">)</span>
</pre></div>
</div>
<p>You can also add paths to the search path using the <a class="reference external" href="http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH">PYTHONPATH</a> environment variable.</p>
</div>
<div class="section" id="multiple-pythons-on-your-computer">
<span id="multiple-pythons"></span><h2>Multiple Pythons on your computer<a class="headerlink" href="#multiple-pythons-on-your-computer" title="Permalink to this headline">¶</a></h2>
<p>This is a practical problem that you are
likely to encounter. Straight away you probably have the system Python
(/usr/bin) and the Anaconda Python. Then if you install PyRaf, CIAO, and CASA you
will get one more Python installation for each analysis package (there are good
reasons for this). <strong>In general, different Python installations cannot
reliably share packages or resources</strong>. Each installation should be considered
as its own local Python universe.</p>
<div class="section" id="installing-within-each-python">
<h3>Installing within each Python<a class="headerlink" href="#installing-within-each-python" title="Permalink to this headline">¶</a></h3>
<p>Now that you know about all the great packages within our Scientific Python
installation, you might want to start using them in your PyRAF or CASA
or CIAO analysis.</p>
<p>If you start digging into Python you will likely come across the technique of
setting the <tt class="docutils literal"><span class="pre">PYTHONPATH</span></tt> environment variable to extend the list of search
paths that Python uses to look for a module. Let’s say you are using CIAO
Python and want to use SciPy functions. You might be tempted to set
<tt class="docutils literal"><span class="pre">PYTHONPATH</span></tt> to point to the directory in EPD where the SciPy modules live.
This will fail because the EPD Python modules were compiled and linked assuming
they’ll be run with EPD Python. With effort you might find a way to make this
work, but in general it’s not a workable solution.</p>
<p>What <em>will</em> often work is to follow the package installation procedure for
each desired package within each Python installation. This assumes that you
have write permission into the directories where the analysis package files
live. Simply enter the appropriate analysis environment, then do then
following:</p>
<ul class="simple">
<li>At the command line do <tt class="docutils literal"><span class="pre">which</span> <span class="pre">python</span></tt> to verify that <tt class="docutils literal"><span class="pre">python</span></tt> is
the correct one from the analysis environment.</li>
<li>Navigate to <a class="reference external" href="http://pypi.python.org/pypi/pip#downloads">http://pypi.python.org/pypi/pip#downloads</a></li>
<li>Download the latest version of pip (<cite>pip-X.Y.tar.gz</cite>)</li>
<li>Untar that file, go in the tar directory, and do <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt></li>
<li>Do <tt class="docutils literal"><span class="pre">rehash</span></tt> (for csh) then <tt class="docutils literal"><span class="pre">which</span> <span class="pre">pip</span></tt> to make sure the new
<tt class="docutils literal"><span class="pre">pip</span></tt> got installed into your analysis environment path.</li>
<li>Now you can do <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre"><package></span></tt> or <tt class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></tt>
for each desired package within
that analysis environment.</li>
</ul>
<p>It’s worth noting that the original example of SciPy will not install with
<tt class="docutils literal"><span class="pre">pip</span></tt>. It requires a very tricky installation from source, so unless SciPy
ships with your favorite analysis environment you are out of luck with that
one.</p>
<p>If you do <em>not</em> have write access to the analysis package directories, then you
need to use the <tt class="docutils literal"><span class="pre">--prefix</span></tt> option in <tt class="docutils literal"><span class="pre">pip</span></tt> to install in a local area and
then set a corresponding <tt class="docutils literal"><span class="pre">PYTHONPATH</span></tt>.</p>
</div>
<div class="section" id="can-we-share-packages">
<h3>Can we share packages?<a class="headerlink" href="#can-we-share-packages" title="Permalink to this headline">¶</a></h3>
<p>In some cases you can successfully share between Pythons. However, <em>this technique is
prone to breaking things in strange ways and we do not recommend it</em>. Nevertheless it is
useful to illustrate how this works.</p>
<p>The first rule is that they need to be the same major version, i.e. all 2.6 or
2.7. This is because Python always includes a major version like
<tt class="docutils literal"><span class="pre">python2.6/</span></tt> in the default search path so Python 2.7 will never find 2.6
packages. The second rule is to install packages using the <tt class="docutils literal"><span class="pre">--user</span></tt> option
in <tt class="docutils literal"><span class="pre">pip</span> <span class="pre">install</span></tt> or <tt class="docutils literal"><span class="pre">setup.py</span> <span class="pre">install</span></tt>. This results in the situation
shown below where each Python can find common packages in the local user area:</p>
<img alt="../_images/antisocial_pythons_trans.png" src="../_images/antisocial_pythons_trans.png" style="width: 650px;" />
<p>Be sure to test that the package you installed works within the other Python
environments.</p>
<div class="admonition caution">
<p class="first admonition-title">Caution</p>
<p class="last">Be very wary of installing a package with <tt class="docutils literal"><span class="pre">--user</span></tt> if one of your Python
installations already contains that package. This is because the local user
version will always take precedence and thus potentially upset that Python
installation. Big analysis packages like CIAO, STSci_Python or CASA are
carefully tested assuming the integrated environment they provide. If you
start mucking this up then all bets are off.</p>
</div>
</div>
</div>
<div class="section" id="virtualenv">
<h2>Virtualenv<a class="headerlink" href="#virtualenv" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="http://virtualenv.org">Virtualenv</a> is a very useful tool for creating isolated
Python environments. As seen in the linux non-root install it provides a way
to make a virtual clone of an existing Python environment. This clone can then
be used as the package installation location.</p>
<p>One use case is wanting to install a new or experimental version of a package
without overwriting the existing production version in your baseline environment.</p>
<p>For a good introductory tutorial see <a class="reference external" href="http://iamzed.com/2009/05/07/a-primer-on-virtualenv/">http://iamzed.com/2009/05/07/a-primer-on-virtualenv/</a>.</p>
</div>
<div class="section" id="final-exercises">
<h2>Final exercises<a class="headerlink" href="#final-exercises" title="Permalink to this headline">¶</a></h2>
<div class="admonition-exercise-intermediate-fully-install-aplpy admonition">
<p class="first admonition-title">Exercise [intermediate]: Fully install APLpy</p>
<p>Go to the <a class="reference external" href="http://aplpy.github.com/install.html">APLpy install page</a> and
read the instructions. Manually install all of the Python package dependencies with the
<tt class="docutils literal"><span class="pre">--user</span></tt> option or try the auto-install script available there.</p>
<p class="last">For extra credit install the <a class="reference external" href="http://montage.ipac.caltech.edu/">Montage</a> C library as discussed on the APLpy
install page. Then try to run the example <a class="reference external" href="../intro/quick-tour.html#making-a-publication-quality-image">Making a publication quality plot</a> that was shown
in the introductory talk. The necessary input files are in the
<tt class="docutils literal"><span class="pre">install_examples.tar</span></tt> file.</p>
</div>
<div class="admonition-exercise-intermediate-install-hdf5-and-pytables admonition">
<p class="first admonition-title">Exercise [intermediate]: Install HDF5 and PyTables</p>
<p class="last">Install <a class="reference external" href="http://www.hdfgroup.org/HDF5/">HDF5</a> and
<a class="reference external" href="http://www.pytables.org/moin">PyTables</a>. This will let you read HDF5 tables
in Python. HDF5 is a data file format which can store and manipulate extremely
large or complex datasets in a scalable manner. It is the baseline for some data-heavy
facilities such as LOFAR.</p>
</div>
<div class="admonition-exercise-expert-install-scipy-and-all-dependencies-from-source admonition">
<p class="first admonition-title">Exercise [expert]: Install SciPy and all dependencies from source</p>
<p>Attempt to follow the instructions for building from source in the <a class="reference external" href="http://www.scipy.org/Installing_SciPy">Installing
SciPy</a> page. (No binary downloads!).
This will be useful if you want to use the very latest development version of
Python or else want to use the system-dependent build optimization so your
numerical libraries are the fastest possible. For most people this is not needed.</p>
<p class="last">If you can do this then consider yourself an expert on Python installation.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../core/core.html" title="Core packages for analysis: IPython, NumPy, and SciPy"
>next</a> |</li>
<li class="right" >
<a href="python_install.html" title="Installing Scientific Python"
>previous</a> |</li>
<li><a href="../index.html">Python4Astronomers 1.1 documentation</a> »</li>
<li><a href="installation.html" >Python Installation and Understanding Packages</a> »</li>
</ul>
</div>
<small>Copyright:
Smithsonian Astrophysical Observatory under terms of
<a rel="license"
href="http://creativecommons.org/licenses/by/3.0/">CC
Attribution 3.0</a></small> <a rel="license"
href="http://creativecommons.org/licenses/by/3.0/"><img alt="Creative Commons
License" style="border-width:0"
src="http://i.creativecommons.org/l/by/3.0/80x15.png" /></a>
</body>
</html>