Introduction
This is a tutorial for starting to use Python in a scientific environment. If you wonder why you should care, please refer to the enthusiastic page. I work on Windows, so these tutorials will refer to Win systems. Anyway, given the fact Python is available for OsX and Linux, it won’t be hard for the reader to figure out the alternative route in those few platform-specific steps.
Goal
At the end of this tutorial, you will have a Python system ready for scientific use. You will learn:
- Differences between Python versions
- How to install new modules/libraries
- What are the common development environments
- What are the most common Python libraries used for science
note: If you want to follow the easy way, you can install Enthought Python Distribution.
Installing Python
Python is an interpreter, a program that reads a text file and and then acts depending on each line of code. A Python script is a text file (with a .py extension) that is read by the Python machine (an executable file, i.e. python.exe). All the rest is the Python environment, a suite of modules, programs, editors, batch files and links to help the programmer.
First one needs to install the Python suite.
Go on www.python.org and download version 2.7 x32 for your system. (note: picking the x32bit is a valid and safe option even for x64 systems).
Unix systems should have Python already installed. Verify that the version is 2.7
What’s up with Python 3? Python had been slowly evolving, but yet to maintains backward compatibility. Only in recent time (8ish years) it was decided to make more substantial changes to the language, and a new main release was born. Since Python has a huge userbase, both 2 and 3 versions are supported until most of the users have done the transition. At the time of writing, the main scientific libraries have just started offering a Python 3 compatible version, but many have not updated yet, so it’s better to play it safe, sticking with 2.7
Now try to execute the python command line. Either look in the installed programs, or open the Command Prompt and type python. You should see something similar to
[code]
Python 2.7 (#1, Feb 28 2010, 00:02:06)
Type "help", "copyright", "credits" or "license" for more information.
>>>
[/code]
This is it. I won’t go into Python syntax at this point. Refer to the next tutorial, or to the official introduction.
Trick: Place ‘python.exe’ in the system path
Trick: Verify that double-clicking on a .py file executes it as Python script. If you are on Windows, you’ll probably just see a flash of a DOS window. This is because once the script is over, the operating system closes it immediately: a quick fix is to end the script with a breaking command (i.e. ‘raw_input()’ or ‘while True: pass’ ), later on we will introduce some developing environments that take care of this problem.
Installing New Modules
Even though “Python comes with batteries included”, that is, the standard library is very extensive and rich, the default installation is not sufficient for most of the scientific applications. Rather then reinventing the wheel, one can rely on external modules or libraries (a set of modules) that extend the language.
Every Python module is a python file, containing the new functionality. We’ll see in the next tutorial how to actually load modules, and the only requirement in order to use it is to indicate to Python where it is located: that means you can just copy the module file into the working directory (i.e. the directory where the interpreter is executed) or include it to the python path, even during execution, and start using it immediately.
Python has also a ‘library’ directory, and in it a ‘site-package’ that is the designated directory for third-parties libraries. All modules in that directory are automatically included to the path, and accessible to every instance of Python
Indeed one would like more sophisticated possibility (i.e. a library could require configuration depending on the OS, or is based on some c++ code that needs to be compiled): for this there is ‘distutils’, and it comes in 2 flavors.
The simplest thing you can come across is the standalone installer: it is built against a specific Python version and OS. You just double click on it, and follow the wizard. You can try it (win) with the Python Image Library.
If the standalone is not provide, the library comes with a setup.py, that contains the installing script. In order to install, you need to call (from command prompt)
[code]
python setup.py install
[/code]
and it will install the library in the proper third-party library directory. For more installation options, refer to the readme.
This is it for installing new modules, but there is an additional tool that makes managing the library easier. setuptools is a module that installs a couple of scripts in the python directory (i.e. ‘python27/scripts’). If you call
[code]
python easy_install.py name_of_the_module
[/code]
the script will check in several databases to find module with the given name, and will install it. If it fails, you can refer to it’s errors for completing the installation (i.e. missing dependency). It doesn’t work 100% of the time, but it’s a very useful tool. It is even more useful in updating the installed modules. You can do just typing
[code]
python easy_install.py –upgrade name_of_the_module
[/code]
Science Libraries
Now that you have all the tools to upgrade your vanilla Python distribution, let’s look for scientist essential libraries.
NumPy: is “the fundamental package for scientific computing with Python. It contains among other things:
- a powerful N-dimensional array object
- sophisticated (broadcasting) functions
- tools for integrating C/C++ and Fortran code
- useful linear algebra, Fourier transform, and random number capabilities”
Scipy: it contains advanced numerical mathematical routines, among all DFFTs, optimization, regression and ODE integration. Most of this tools are compiled Fortran or C programs, so they perform fast. Scipy is also the name of the community for the scientific use of Python.
Matplotlib: enables graphical output, plots and graphs. It can be used simple mathematical graphical plotter, with a syntax similar to matlab (pylab). In addition, it provides an extremely powerful api for more complex applications.
Try to install all these 3 libraries with any of the methods from the previous section. We will learn a little bit of how to use them in the next tutorial, but you should always refer to their documentation for knowing how to use them.
Choosing the Environment
The last thing to prepare is the developing environment, that is which editor and pipeline you want to use for coding. I will list here few options that were very convenient in my experience in the lab, but they are not the only or the best. In the next tutorial we will employ each of this tools, but now let’s just list them:
Idle
Notepad++ (or any other augmented text-editor)
Ipython
Spyder
Eclipse
acne medication contrary – acne treatment incident acne medication square
inhalers for asthma lore – asthma medication westward asthma medication smash
uti treatment bearer – uti antibiotics chocolate treatment for uti whenever
prostatitis medications desert – prostatitis medications sleepy prostatitis treatment chance
valtrex pills lett – valtrex online extend valacyclovir pills virtue
claritin pills acquaintance – claritin pills fate claritin pills chief
claritin pills apart – claritin pills vain claritin german
priligy tin – dapoxetine organ dapoxetine rain
promethazine wary – promethazine recall promethazine hunter
ascorbic acid utter – ascorbic acid wear ascorbic acid fact
florinef pills cow – fludrocortisone spring prevacid freedom
clarithromycin pills english – mesalamine country cytotec pills issue
dulcolax 5mg cost – buy loperamide 2 mg for sale buy generic liv52
?? ??????????? ???????? ???-????
https://solotutos.com/artista-destroza-snapchat-y-la-escultura-ar-de-jeff-koon/
????? ????, ?? ???????? ???????? ???? ? ????????: url=https://d3buuag9gcp8bb.cloudfront.net/news/sebastian-errazuriz-vandalises-jeff-koons-snapchat-ar-balloon-dog-art-051017]https://d3buuag9gcp8bb.cloudfront.net/news/sebastian-errazuriz-vandalises-jeff-koons-snapchat-ar-balloon-dog-art-051017
rabeprazole brand – buy aciphex 20mg for sale order motilium 10mg pill
order cotrimoxazole 960mg pill – tobrex over the counter cost tobramycin
order zovirax creams – buy hydroquinone cream for sale order dydrogesterone 10mg generic
order dapagliflozin 10mg generic – order acarbose without prescription precose 25mg generic
order griseofulvin online – buy gemfibrozil for sale order gemfibrozil generic
buy generic vasotec – generic vasotec 10mg zovirax without prescription
dimenhydrinate 50mg canada – dramamine for sale online buy risedronate 35mg for sale
piroxicam online order – buy piroxicam 20mg online exelon cheap
buy monograph 600mg online cheap – order etodolac 600mg without prescription pletal 100mg pills
nootropil 800mg pill – buy secnidazole without a prescription buy generic sinemet online
hydroxyurea ca – buy generic crixivan buy robaxin 500mg generic
order divalproex 500mg pills – purchase mefloquine generic buy generic topiramate 200mg
how to get disopyramide phosphate without a prescription – chlorpromazine order online buy thorazine pills for sale
cytoxan tablets – atomoxetine generic buy generic vastarel for sale
order spironolactone sale – buy generic carbamazepine for sale purchase revia online
buy flexeril medication – buy flexeril 15mg order vasotec 10mg sale
order zofran 8mg pill – buy oxybutynin tablets requip over the counter
order ascorbic acid sale – bromhexine generic order compro without prescription
durex gel where to buy – durex gel purchase online where to buy latanoprost without a prescription
order arava 10mg online – alfacip canada cartidin canada
minoxidil price – dutas pills purchase finasteride online cheap
order generic tenormin – coreg 25mg for sale coreg us
where to buy verapamil without a prescription – buy tenoretic generic buy tenoretic without a prescription
atorvastatin tablets – order zestril pills nebivolol price
where to buy lasuna without a prescription – order himcolin online cheap buy himcolin generic
gasex order online – gasex brand purchase diabecon generic
cheap finasteride pill – alfuzosin canada order uroxatral generic
buy hytrin for sale – order tamsulosin 0.2mg pills buy priligy pills for sale
order trileptal 600mg online cheap – buy levothroid pill cheap synthroid 75mcg
buy lactulose bottles – betahistine for sale online betahistine price
imusporin drug – generic methotrexate 2.5mg where to buy colchicine without a prescription
deflazacort usa – cheap calcort generic brimonidine drug
buy besivance generic – sildamax sale cheap sildamax pill
neurontin us – buy motrin 400mg for sale buy sulfasalazine medication
order generic probenecid 500 mg – buy tegretol generic order carbamazepine without prescription
brand celebrex 200mg – order urispas generic indocin 50mg sale