顯示具有 programing 標籤的文章。 顯示所有文章
顯示具有 programing 標籤的文章。 顯示所有文章

2014年6月7日 星期六

How do I get the path of the current executed file in python?





Reference:
http://stackoverflow.com/questions/2632199/how-do-i-get-the-path-of-the-current-executed-file-in-python



Following are for copy&paste:
#
some_path/module_locator.py:
def we_are_frozen():
    # All of the modules are built-in to the interpreter, e.g., by py2exe
    return hasattr(sys, "frozen")

def module_path():
    encoding = sys.getfilesystemencoding()
    if we_are_frozen():
        return os.path.dirname(unicode(sys.executable, encoding))
    return os.path.dirname(unicode(__file__, encoding))
some_path/main.py:
import module_locator
my_path = module_locator.module_path()

2014年5月28日 星期三

Python, How to install library for portable python by using distribute on windows

For example:

1. Download distrubute
2. Unzip distribute, ex: "distribute-0.7.3"
3. Move "distribute-0.7.3" to "D:\PortablePython" (That is my portable python location).
4. Open command line
5. Enter following command without quotes:
    - "d:"
    - "cd "PortablePython"
    -  "Python-Portable.exe distribute-0.7.3\setup.py install"

If you want install package "pygal", just enter following command without quotes:
- "cd D:\PortablePython\App\Scripts"
- "easy_install-2.7.exe pygal"

==============================================================
Updated, another way:

Using "pip":
https://pip.pypa.io/en/latest/installing.html
http://www.codedata.com.tw/python/python-tutorial-the-1st-class-3-hello-world-traditional-chinese-edition