$ sudo apt-get install build-essential python-dev libblas-dev liblapack-dev gfortran python-pip git libzmq3 libzmq3-dev
$ sudo pip install pip --upgrade $ sudo pip install virtualenvwrapper
Adicione as seguintes linhas no seu ~/.bashrc (ou ~/.bash_profile)
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel source /usr/local/bin/virtualenvwrapper.sh
Clone o repositório deste curso:
$ git clone https://github.com/herberthamaral/curso-python-sec2015.git
$ mkvirtualenv -a $(pwd)/curso-python-sec2015 curso-python-sec2015 $ pip install -r requirements.txt $ pip install "ipython[all]"
Agora sente e espere porque vai demorar :)
In [4]:
print "Olá Mundo!" #Este é o nosso hello world e este é um comentário :)
In [26]:
%pylab inline
In [27]:
import numpy as np
x = np.linspace(0, 5)
plot(x, cos(x))
Out[27]:
In [28]:
from sklearn.linear_model import Perceptron
perceptron = Perceptron()
perceptron.fit([[0,0], [0,1], [1,0], [1,1]], [0,1,1,1]) # porta OR
perceptron.predict([0,1])
Out[28]:
In [20]:
import numpy as np
matriz = np.matrix([[1,2,3,4], [5,6,7,8]])
matriz
Out[20]:
In [22]:
matriz.T #transposta
Out[22]:
In [25]:
matriz*matriz.T
Out[25]:
In [33]:
import sympy as sp
sp.sqrt(8)
Out[33]:
In [51]:
x = sp.symbols('x')
sp.diff(sp.sin(x)*sp.exp(x),x)
Out[51]:
In [53]:
sp.integrate(sp.sin(x), x)
Out[53]:
In [3]:
import sqlite3
conn = sqlite3.connect('exemplo.db')
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS pessoas (id integer primary key, nome text, telefone text, data_nascimento date)")
c.execute("""INSERT INTO pessoas (nome, telefone, data_nascimento)
VALUES ('Herberth Amaral','32222222', '1988-11-05')""")
conn.commit()
c.execute('SELECT * from pessoas')
c.fetchone()
Out[3]:
Execute no terminal:
$ python web.py
Logo em seguida abra seu navegador em http://localhost:5000/