开发者

How can I run redemo.py (or equivalent) on a Mac?

In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts cal开发者_高级运维led redemo.py. It's a simple tk application for testing regular expressions.

I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of the Python installation on my Mac. Ideas?


You can view the script directly from the python svn repository here and can download it:

curl http://svn.python.org/view/*checkout*/python/trunk/Tools/scripts/redemo.py?content-type=text%2Fplain > redemo.py
/usr/bin/python redemo.py

It seems to work just fine as is on OS X 10.6 with python 2.6.


Firstly, we should check whether the redemo.py is included in our system by using:

find / -name redemo.py # you can change the root searching path from `/` to other folder if you know the more specific path where python is installed.

Because some python distribution provider (e.g. Anaconda or default python in Linux/Unix distr.) sometimes will exclude this demo tool when install the python in our system.


If we found the redemo.py file within some python environments (assuming we have more than one python installed) then we can run it directly:

/right/path/python /right/path/redemo.py

But if there is no redemo.py file found in our system, we can still download this demo tool from official code repo (now at GitHub) and play with it.

curl https://raw.githubusercontent.com/python/cpython/3.6/Tools/demo/redemo.py > redemo.py
python redemo.py # Note the version is 3.6 in download path.


Mac OS X comes with Python pre-installed. As of 10.6.2 it has Python 2.6.1 found at /usr/bin/python. Copy redemo.py to your Mac. Make sure you have X11.app running and open a terminal (Terminal.app is available by default) and just run:

% python /path/to/redemo.py

Assuming there aren't any Win32 specific hooks in this script, it should execute.


Install Python on your Mac, then copy the script over? It should work fine on any Python installation.


Python is part of OS X, but sometimes it's a bit out of date: http://www.python.org/download/mac/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜