天天看點

ReText安裝與使用(Windows下)

      retext 是一個使用 markdown 文法和 restructuredtext (rest) 結構的文本編輯器,編輯的内容支援導出到 pdf、odt 和 html 以及純文字,支援即時預覽、網頁生成以及 html 文法高亮、全屏模式等。

     1.下載下傳并安裝python.

ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)

安裝我就不說了,我是安裝到e:\python34

ReText安裝與使用(Windows下)

 2.下載下傳并安裝pyqt5,下載下傳位址:

    http://www.riverbankcomputing.co.uk/software/pyqt/download5

請根據自己作業系統位數選擇下載下傳:

ReText安裝與使用(Windows下)

 下載下傳完成後輕按兩下安裝

3.設定環境變量

ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)

變量名:pythonpath

變量值:e:\python34\lib\;e:\python34\lib\site-packages\

變量值請根據自己實際的安裝路徑适當修改,你懂的哈。

同理繼續添加qt_qpa_platform_plugin_path系統變量

變量名:qt_qpa_platform_plugin_path

變量值:e:\python34\lib\site-packages\pyqt5\plugins\platforms

然後選中path系統環境變量,然後點“編輯”,在變量值最前面添加上:

e:\python34;e:\python34\lib\site-packages\pyqt5;

4.下載下傳并安裝easy_install工具

  首先下載下傳ez_setup.py,你可以自己根據檔案名去google,也可以根據我提供的檔案内容自己建立

ReText安裝與使用(Windows下)

#!/usr/bin/env python  

""" 

setuptools bootstrapping installer. 

run this script to install or upgrade setuptools. 

"""  

import os  

import shutil  

import sys  

import tempfile  

import zipfile  

import optparse  

import subprocess  

import platform  

import textwrap  

import contextlib  

import warnings  

from distutils import log  

try:  

    from urllib.request import urlopen  

except importerror:  

    from urllib2 import urlopen  

    from site import user_site  

    user_site = none  

default_version = "15.0"  

default_url = "https://pypi.python.org/packages/source/s/setuptools/"  

default_save_dir = os.curdir  

def _python_cmd(*args):  

    """ 

    execute a command. 

    return true if the command succeeded. 

    """  

    args = (sys.executable,) + args  

    return subprocess.call(args) == 0  

def _install(archive_filename, install_args=()):  

    """install setuptools."""  

    with archive_context(archive_filename):  

        # installing  

        log.warn('installing setuptools')  

        if not _python_cmd('setup.py', 'install', *install_args):  

            log.warn('something went wrong during the installation.')  

            log.warn('see the error message above.')  

            # exitcode will be 2  

            return 2  

def _build_egg(egg, archive_filename, to_dir):  

    """build setuptools egg."""  

        # building an egg  

        log.warn('building a setuptools egg in %s', to_dir)  

        _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)  

    # returning the result  

    log.warn(egg)  

    if not os.path.exists(egg):  

        raise ioerror('could not build the egg.')  

class contextualzipfile(zipfile.zipfile):  

    """supplement zipfile class to support context manager for python 2.6."""  

    def __enter__(self):  

        return self  

    def __exit__(self, type, value, traceback):  

        self.close()  

    def __new__(cls, *args, **kwargs):  

        """construct a zipfile or contextualzipfile as appropriate."""  

        if hasattr(zipfile.zipfile, '__exit__'):  

            return zipfile.zipfile(*args, **kwargs)  

        return super(contextualzipfile, cls).__new__(cls)  

@contextlib.contextmanager  

def archive_context(filename):  

    unzip filename to a temporary directory, set to the cwd. 

    the unzipped target is cleaned up after. 

    tmpdir = tempfile.mkdtemp()  

    log.warn('extracting in %s', tmpdir)  

    old_wd = os.getcwd()  

    try:  

        os.chdir(tmpdir)  

        with contextualzipfile(filename) as archive:  

            archive.extractall()  

        # going in the directory  

        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])  

        os.chdir(subdir)  

        log.warn('now working in %s', subdir)  

        yield  

    finally:  

        os.chdir(old_wd)  

        shutil.rmtree(tmpdir)  

def _do_download(version, download_base, to_dir, download_delay):  

    """download setuptools."""  

    egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'  

                       % (version, sys.version_info[0], sys.version_info[1]))  

        archive = download_setuptools(version, download_base,  

                                      to_dir, download_delay)  

        _build_egg(egg, archive, to_dir)  

    sys.path.insert(0, egg)  

    # remove previously-imported pkg_resources if present (see  

    # https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).  

    if 'pkg_resources' in sys.modules:  

        del sys.modules['pkg_resources']  

    import setuptools  

    setuptools.bootstrap_install_from = egg  

def use_setuptools(  

        version=default_version, download_base=default_url,  

        to_dir=default_save_dir, download_delay=15):  

    ensure that a setuptools version is installed. 

    return none. raise systemexit if the requested version 

    or later cannot be installed. 

    to_dir = os.path.abspath(to_dir)  

    # prior to importing, capture the module state for  

    # representative modules.  

    rep_modules = 'pkg_resources', 'setuptools'  

    imported = set(sys.modules).intersection(rep_modules)  

        import pkg_resources  

        pkg_resources.require("setuptools>=" + version)  

        # a suitable version is already installed  

        return  

    except importerror:  

        # pkg_resources not available; setuptools is not installed; download  

        pass  

    except pkg_resources.distributionnotfound:  

        # no version of setuptools was found; allow download  

    except pkg_resources.versionconflict as vc_err:  

        if imported:  

            _conflict_bail(vc_err, version)  

        # otherwise, unload pkg_resources to allow the downloaded version to  

        #  take precedence.  

        del pkg_resources  

        _unload_pkg_resources()  

    return _do_download(version, download_base, to_dir, download_delay)  

def _conflict_bail(vc_err, version):  

    setuptools was imported prior to invocation, so it is 

    unsafe to unload it. bail out. 

    conflict_tmpl = textwrap.dedent(""" 

        the required version of setuptools (>={version}) is not available, 

        and can't be installed while this script is running. please 

        install a more recent version first, using 

        'easy_install -u setuptools'. 

        (currently using {vc_err.args[0]!r}) 

        """)  

    msg = conflict_tmpl.format(**locals())  

    sys.stderr.write(msg)  

    sys.exit(2)  

def _unload_pkg_resources():  

    del_modules = [  

        name for name in sys.modules  

        if name.startswith('pkg_resources')  

    ]  

    for mod_name in del_modules:  

        del sys.modules[mod_name]  

def _clean_check(cmd, target):  

    run the command to download target. 

    if the command fails, clean up before re-raising the error. 

        subprocess.check_call(cmd)  

    except subprocess.calledprocesserror:  

        if os.access(target, os.f_ok):  

            os.unlink(target)  

        raise  

def download_file_powershell(url, target):  

    download the file at url to target using powershell. 

    powershell will validate trust. 

    raise an exception if the command cannot complete. 

    target = os.path.abspath(target)  

    ps_cmd = (  

        "[system.net.webrequest]::defaultwebproxy.credentials = "  

        "[system.net.credentialcache]::defaultcredentials; "  

        "(new-object system.net.webclient).downloadfile(%(url)r, %(target)r)"  

        % vars()  

    )  

    cmd = [  

        'powershell',  

        '-command',  

        ps_cmd,  

    _clean_check(cmd, target)  

def has_powershell():  

    """determine if powershell is available."""  

    if platform.system() != 'windows':  

        return false  

    cmd = ['powershell', '-command', 'echo test']  

    with open(os.path.devnull, 'wb') as devnull:  

        try:  

            subprocess.check_call(cmd, stdout=devnull, stderr=devnull)  

        except exception:  

            return false  

    return true  

download_file_powershell.viable = has_powershell  

def download_file_curl(url, target):  

    cmd = ['curl', url, '--silent', '--output', target]  

def has_curl():  

    cmd = ['curl', '--version']  

download_file_curl.viable = has_curl  

def download_file_wget(url, target):  

    cmd = ['wget', url, '--quiet', '--output-document', target]  

def has_wget():  

    cmd = ['wget', '--version']  

download_file_wget.viable = has_wget  

def download_file_insecure(url, target):  

    """use python to download the file, without connection authentication."""  

    src = urlopen(url)  

        # read all the data in one block.  

        data = src.read()  

        src.close()  

    # write all the data in one block to avoid creating a partial file.  

    with open(target, "wb") as dst:  

        dst.write(data)  

download_file_insecure.viable = lambda: true  

def get_best_downloader():  

    downloaders = (  

        download_file_powershell,  

        download_file_curl,  

        download_file_wget,  

        download_file_insecure,  

    viable_downloaders = (dl for dl in downloaders if dl.viable())  

    return next(viable_downloaders, none)  

def download_setuptools(  

        to_dir=default_save_dir, delay=15,  

        downloader_factory=get_best_downloader):  

    download setuptools from a specified location and return its filename. 

    `version` should be a valid setuptools version number that is available 

    as an sdist for download under the `download_base` url (which should end 

    with a '/'). `to_dir` is the directory where the egg will be downloaded. 

    `delay` is the number of seconds to pause before an actual download 

    attempt. 

    ``downloader_factory`` should be a function taking no arguments and 

    returning a function for downloading a url to a target. 

    # making sure we use the absolute path  

    zip_name = "setuptools-%s.zip" % version  

    url = download_base + zip_name  

    saveto = os.path.join(to_dir, zip_name)  

    if not os.path.exists(saveto):  # avoid repeated downloads  

        log.warn("downloading %s", url)  

        downloader = downloader_factory()  

        downloader(url, saveto)  

    return os.path.realpath(saveto)  

def _build_install_args(options):  

    build the arguments to 'python setup.py install' on the setuptools package. 

    returns list of command line arguments. 

    return ['--user'] if options.user_install else []  

def _parse_args():  

    """parse the command line for options."""  

    parser = optparse.optionparser()  

    parser.add_option(  

        '--user', dest='user_install', action='store_true', default=false,  

        help='install in user site package (requires python 2.6 or later)')  

        '--download-base', dest='download_base', metavar="url",  

        default=default_url,  

        help='alternative url from where to download the setuptools package')  

        '--insecure', dest='downloader_factory', action='store_const',  

        const=lambda: download_file_insecure, default=get_best_downloader,  

        help='use internal, non-validating downloader'  

        '--version', help="specify which version to download",  

        default=default_version,  

        '--to-dir',  

        help="directory to save (and re-use) package",  

        default=default_save_dir,  

    options, args = parser.parse_args()  

    # positional arguments are ignored  

    return options  

def _download_args(options):  

    """return args for download_setuptools function from cmdline args."""  

    return dict(  

        version=options.version,  

        download_base=options.download_base,  

        downloader_factory=options.downloader_factory,  

        to_dir=options.to_dir,  

def main():  

    """install or upgrade setuptools and easyinstall."""  

    options = _parse_args()  

    archive = download_setuptools(**_download_args(options))  

    return _install(archive, _build_install_args(options))  

if __name__ == '__main__':  

    sys.exit(main())  

    輕按兩下ez_setup.py開始安裝easy_install.

5.cmd打開指令行視窗,切換到e:\python34\scripts目錄下,依次順序執行如下指令:

         pip install pygments

         pip install markdown

         pip install docutils

         pip install markups

6.下載下傳并解壓retext

ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)

 解壓retext到任意盤符,然後解壓圖示檔案壓縮包,把得到的所有圖示檔案copy到retext的icons檔案夾下:如圖

ReText安裝與使用(Windows下)

 我的retext是解壓到e盤,這樣retext就可以使用了,

ReText安裝與使用(Windows下)

 當然為了友善起見,你也可以把retext.py檔案發送到桌面快捷方式。

為了實作把retext放入u盤,實作便攜式安裝。

ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)

 然後在u盤根目錄下建立一個retext.bat批處理檔案:

ReText安裝與使用(Windows下)

rem retext startup batch file  

rem -------------------------  

rem determine drive letter of batchfile  

for /f "delims=\" %%d in ('cd') do set curdrv=%%d  

echo %curdrv%  

rem set envs using current drive letter if envs not set for usb sticks  

rem rem them out if you have the envs set  

set pythonpath=%curdrv%\python34\lib;%curdrv%\python34\lib\site-packages  

set path=%curdrv%\python34;%curdrv%\python34\lib\site-packages\pyqt5\bin;%path%  

rem start retext  

start /b %curdrv%\python34\pythonw.exe %cd%\retext.py  

 以後隻要輕按兩下retext.bat檔案即可打開retext.

    retext主界面如圖:

ReText安裝與使用(Windows下)

 是不是覺得so beautiful?如果你也有同感,就跟我一起玩玩它吧!其實哥可不是什麼外貌協會,retext吸引我的是它支援md導出為html檔案和pdf檔案,這是一大亮點,對于我來說。

ReText安裝與使用(Windows下)
ReText安裝與使用(Windows下)

      ok,夜深了已是00:20,打完收工睡覺覺!!!

轉載:http://iamyida.iteye.com/blog/2200121