Python: Difference between revisions

From 太極
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
= How to run a python code =
= Basic =
== How to run a python code ==
<pre>
<pre>
python mypython.py
python mypython.py
</pre>
</pre>


= Install a new module =
== Install a new module ==


[https://pypi.python.org/pypi The Python Package Index (PyPI)] is the definitive list of packages (or modules)
[https://pypi.python.org/pypi The Python Package Index (PyPI)] is the definitive list of packages (or modules)
Line 23: Line 24:
</pre>
</pre>


= How to list all installed modules =
== How to list all installed modules ==
<pre>
<pre>
help('modules')
help('modules')
</pre>
</pre>


= How to find the location of installed modules =
== How to find the location of installed modules ==
There are different ways
There are different ways
# python -v
# python -v
Line 35: Line 36:


Using this way, I find the 'RPi' module is installed under /usr/lib/python2.7/dist-packages.
Using this way, I find the 'RPi' module is installed under /usr/lib/python2.7/dist-packages.
== if __name__ == "__main__": ==
http://stackoverflow.com/questions/419163/what-does-if-name-main-do


= Projects based on python =
= Projects based on python =

Revision as of 19:37, 13 April 2014

Basic

How to run a python code

python mypython.py

Install a new module

The Python Package Index (PyPI) is the definitive list of packages (or modules)

sudo apt-get install python-pip
pip install SomePackage
pip show --files SomePackage
pip install --upgrade SomePackage
pip uninstall SomePackage

If a package has been bundled by its creator using the standard approach to bundling modules (with Python’s distutils tool), all you need to do is download the package, uncompress it and type:

python setup.py install

How to list all installed modules

help('modules')

How to find the location of installed modules

There are different ways

  1. python -v
  2. import MODULENAME
  3. help('MODULENAME')

Using this way, I find the 'RPi' module is installed under /usr/lib/python2.7/dist-packages.

if __name__ == "__main__":

http://stackoverflow.com/questions/419163/what-does-if-name-main-do

Projects based on python

Qt for GUI development