Python

From GHER

(Difference between revisions)
Jump to: navigation, search
(Installation)
(Blanked the page)
 
Line 1: Line 1:
-
= Documentation =
 
-
=== Web ===
 
-
* http://docs.python.org/tut/
 
-
* https://developers.google.com/edu/python/introduction?hl=en (tutorial + exercises)
 
-
* http://www.python-course.eu
 
-
* http://www.learnpython.org (with online code execution)
 
-
* https://pythonprogramming.net
 
-
 
-
=== Learning platforms ===
 
-
* [https://www.udacity.com/course/programming-foundations-with-python--ud036 Programming Foundations with Python Learn Object-Oriented Programming] (7 weeks)
 
-
* [https://www.codecademy.com/learn/python Code Academy] (13 hours)
 
-
 
-
=== Youtube ===
 
-
* [https://www.youtube.com/watch?v=cpPG0bKHYKc Python Beginner Tutorial] (For Absolute Beginners) (4 parts)
 
-
* [https://www.youtube.com/watch?v=tKTZoB2Vjuk Google Python Class] (7 X 30 minutes)
 
-
* [https://www.youtube.com/watch?v=9uq3w6JJS00 Zero to Hero with Python] (11 hours)
 
-
 
-
=== Books ===
 
-
* [http://learnpythonthehardway.org/book/ ''Learn Python the hard way''], Z.A. Shaw, 2013
 
-
* ''Learning Python'', 5th Edition, M. Lutz, 2013
 
-
* ''Python Programming: An Introduction to Computer Science'', J.M. Zelle, 2002
 
-
Complete list: https://wiki.python.org/moin/PythonBooks
 
-
 
-
= Installation =
 
-
 
-
== General python ==
 
-
 
-
Depends mainly on the Operating System and on the user ability.
 
-
 
-
=== Hard way ===
 
-
Download source and compile: https://www.python.org/downloads/
 
-
 
-
For Python 3.6.0:
 
-
./configure --enable-optimizations
 
-
make
 
-
make test
 
-
sudo make install
 
-
Note that the ''make'' step can take a while.
 
-
 
-
=== Normal way ===
 
-
Use installer or package manager
 
-
 
-
* [https://www.python.org/downloads/windows/ Windows]
 
-
* [https://www.python.org/downloads/mac-osx/ Mac OS]
 
-
* Linux: package manager:
 
-
python2.x and python2.x-dev packages
 
-
 
-
=== Easy way ===
 
-
Python distributions such as:
 
-
* [https://www.continuum.io/downloads Anaconda] (free)
 
-
* [https://www.enthought.com/products/canopy/ Enthought Canopy] (free and commercial)
 
-
* [http://python-xy.github.io/ Python(x,y)] (free, Windows only)
 
-
+ other possibilities
 
-
 
-
=== Linux ===
 
-
 
-
Add Arthur's notes from email
 
-
 
-
== Modules ==
 
-
 
-
Example: [http://www.scipy.org/ SciPy]: mathematics, science, and engineering
 
-
 
-
=== Easy way ===
 
-
Windows, Linux, Mac: use Scientific Python distribution
 
-
 
-
=== Intermediate ===
 
-
* Linux: package manager
 
-
* Mac: [https://www.macports.org/ MacPorts], [http://brew.sh/ Homebrew]
 
-
 
-
=== Harder  ===
 
-
Build from source
 
-
 
-
python setup.py install
 
-
 
-
=== General ===
 
-
 
-
* Use [https://pypi.python.org/pypi/pip pip] () tool whenever possible
 
-
* Use virtualenv (virtual environment) to deal with different versions of packages
 
-
* Avoid mixing installation methods within a given machine
 
-
 
-
== Using pip to manage modules ==
 
-
 
-
''pip'' = recommended tool for installing Python packages
 
-
 
-
=== Installation ===
 
-
* Included in recent Python version
 
-
* Otherwise: download and run get-pip.py (https://pip.pypa.io/en/stable/installing/\#install-pip)
 
-
python get-pip.py
 
-
 
-
=== Usage ===
 
-
See the full [https://pip.pypa.io/en/stable/ documentation for pip]. A few basic examples:
 
-
* Install latest version + dependencies:
 
-
pip install PackageName
 
-
* Specify exact version:
 
-
pip install PackageName==x.y.z
 
-
* Specify minimum version:
 
-
pip install 'Package>=x.y.z'
 
-
* Uninstall packages:                 
 
-
pip uninstall
 
-
* List installed packages:
 
-
pip list
 
-
Example of output:
 
-
aptoncd (0.1.98-bzr117-1.2)
 
-
...
 
-
xhtml2pdf (0.0.6)
 
-
zope.interface (3.6.1)
 
-
* Output installed packages in requirements format:
 
-
pip freeze
 
-
Example of output:
 
-
aptoncd===0.1.98-bzr117-1.2
 
-
...
 
-
zope.interface==3.6.1
 
-
 
-
* Show information about installed packages:
 
-
pip show numpy
 
-
will return something like:
 
-
---
 
-
Metadata-Version: 2.0
 
-
Name: numpy
 
-
Version: 1.11.1
 
-
Summary: NumPy: array processing for numbers, strings, records, and objects.
 
-
Home-page: http://www.numpy.org
 
-
 
-
= Useful modules =
 
-
 
-
== Science and numeric ==
 
-
 
-
* [http://www.numpy.org/ numpy]: scientific computing,
 
-
* [http://scipy.org/scipylib/index.html scipy]: scientific and technical computing.
 
-
 
-
== Data analysis ==
 
-
 
-
* [http://pandas.pydata.org/ pandas]: data structures and data analysis tools.
 
-
 
-
== Graphical User Interface ==
 
-
 
-
* Tkinter
 
-
 
-
== Plotting ==
 
-
 
-
* [http://matplotlib.org/ matplotlib]: 2D plotting library,
 
-
* [http://bokeh.pydata.org/en/latest/ bokeh]: interactive visualisation,
 
-
* [https://plot.ly/python/ plotly]: browser-based plotting and analytics platform,
 
-
* [http://matplotlib.org/basemap/ Basemap toolkit]: library for plotting 2D data on maps.
 
-
 
-
== For notebooks ==
 
-
 
-
* [https://github.com/jupyter/nbdime ndime]: Notebook Diff and Merge tools
 
-
 
-
= Running python code =
 
-
 
-
== Bash ==
 
-
Edit, then run in a shell:
 
-
python mycode.py
 
-
or if the ''shebang'' #!/usr/bin/python is present at the 1st line
 
-
mycode.py
 
-
 
-
== Interactive python ==
 
-
[http://ipython.org/ ipython] provides auto-completion, exploring objects, ...
 
-
And the so-called [https://ipython.org/ipython-doc/3/interactive/magics.html ''magic'' functions]:
 
-
* %run: Run the named file inside IPython as a program
 
-
* %timeit: Time execution of a Python statement or expression
 
-
* %who: Print all interactive variables, with some minimal formatting
 
-
 
-
== Integrated Development Environments (IDE) ==
 
-
Editor + build automation tools + debugger
 
-
 
-
* [https://atom.io/ Atom]
 
-
* [https://eclipse.org/downloads/ Eclipse]
 
-
* [https://www.jetbrains.com/pycharm/ PyCharm]
 
-
Complete list: https://wiki.python.org/moin/PythonEditors
 
-
 
-
== Virtual environments (venv) ==
 
-
 
-
'''Goal:''' to keep the dependencies required by different projects in separate places: http://docs.python-guide.org/en/latest/dev/virtualenvs/
 
-
 
-
=== Installation ===
 
-
See https://virtualenvwrapper.readthedocs.io/en/latest/install.html for details
 
-
* Install modules
 
-
pip install virtualenv
 
-
pip install virtualenvwrapper
 
-
* Create a directory where the environments will be stored
 
-
mkdir ~/Envs
 
-
* Assign the variable WORKON_HOME, PROJECT_HOME and source virtualenvwrapper.sh
 
-
export WORKON_HOME=/home/ctroupin/Software/Python/Envs
 
-
export PROJECT_HOME=/home/ctroupin/Projects/Python
 
-
source /usr/local/bin/virtualenvwrapper.sh
 
-
These 3 lines can be added in the ''.bashrc'' file.
 
-
 
-
=== Removal ===
 
-
 
-
If you have virtualenvwrapper installed:
 
-
rmvirtualenv
 
-
otherwise remove recursively the folder containing the environment.
 
-
 
-
=== venv usage ===
 
-
 
-
* First, create a new environment
 
-
mkvirtualenv Diva
 
-
You know that you are inside the environment because of the ''(Diva)'' written before your username:
 
-
(Diva) ctroupin@gher13 ~ $
 
-
* To close the session:
 
-
deactivate
 
-
* To work on a given environment, no need to create it, just type:
 
-
workon Diva
 
-
 
-
=== venv with different python versions ===
 
-
 
-
One can specify the python version using the '''-p''' flag of ''mkvirtualenv'', for example:
 
-
mkvirtualenv -p python3.6 Diva-python3.6
 
-
 
-
=== Configure matplotlib with virtualenv ===
 
-
 
-
The file '''matplotlibrc''' can be edited in order to customize the plots:<br>
 
-
http://matplotlib.org/users/customizing.html
 
-
 
-
To find its location:
 
-
import matplotlib
 
-
matplotlib.matplotlib_fname()
 
-
If you work with a virtual environment, there is an additional file located in
 
-
${ENVDIR}/lib/python3.6/site-packages/matplotlib/mpl-data
 
-
where ENVDIR is the path to the main directory of the environment.
 
-
 
-
== [[Jupyter notebooks]] ==
 
-
 
-
Web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text.
 
-
 
-
= Troubleshooting =
 
-
 
-
== Install QT4 with python 3 ==
 
-
 
-
Error message:
 
-
...
 
-
from PyQt4 import QtCore, QtGui
 
-
ModuleNotFoundError: No module named 'PyQt4'
 
-
 
-
Follow instructions from:<br>
 
-
http://stackoverflow.com/questions/7942887/how-to-configure-pyqt4-for-python-3-in-ubuntu
 
-
 
-
== Install mpl_toolkits in virtualenv ==
 
-
 
-
Sometimes it is not possible to install via pip, in these cases one has to resort to other methods.<br>
 
-
https://gist.github.com/yosemitebandit/91b4143ffad899aebef8
 
-
 
-
= Other Python tools =
 
-
 
-
== [[Django|Django]] ==
 

Latest revision as of 07:55, 27 June 2017

Personal tools