cannot execute binary file (Python 3.0.1)
Ned Deily
nad at acm.org
Sun Mar 1 04:52:40 EST 2009
In article
<b756d6fc-4959-4412-8bb7-7ce94fabf821 at w34g2000yqm.googlegroups.com>,
cf29 <charly.founes at gmail.com> wrote:
> On Mac OS 10.5.6, I updated Python to version 3.0.1.
> When I want to run a py file, I get an error:
> xxx:~ xxx$ cd '/Users/xxx/Documents/programmingPractice/' && '/usr/
> local/bin/python' '/Users/xxx/Documents/programmingPractice/
> python_file.py' && echo Exit status: $? && exit 1
> -bash: /usr/local/bin/python: cannot execute binary file
>
> This wasn't an issue with Python 2.6, please let me know how to solve
> this problem.
It appears you are trying to run a python script by double-clicking on
it and that Python Launcher.app is the default application associated
with .py files. The default setting in Python Launcher is to use the
python linked to /use/local/bin/pythonw. By default, the OS X 3.0.1
installer does not install or modify the links in /usr/local/bin/,
unlike 2.x installers. That is a problem for Python Launcher. Here are
a few options, assuming you used the 3.0.1 python.org installer:
1. You can start up the installer again, choose Customize, and then
select and install the "UNIX command-line tools" package.
/usr/local/bin/pythonw will now point out at python 3.0.1 rather than
python 2.6.
2. Launch Python Launcher and change its Preferences. Python Launcher
should be in the /Applications/Python 3.0 folder. Select Preferences
and in the Interpreter field enter the full path to python3.0, which is:
/Library/Frameworks/Python.framework/Versions/3.0/bin/python3.0
3. Use IDLE instead of Python Launcher to run scripts. Just launch IDLE
(it's also in /Applications/Python 3.0) and open the script file from
IDLE's menu bar. Or drag-drop the script onto the IDLE icon in the
Dock. If you want to be able to double-click on the file in the Finder,
you'll need to change the default application associated with .py files.
In a Finder window or the desktop select your python script file but
don't double-click it. Instead, choose the FInder's "Get Info" command
and in the resulting Info window choose IDLE 3.0.1 in the "Open with"
list. To open all .py files with IDLE, if necessary click on the
padlock in the lower right-hand corner of the Info window to
authenticate, then click on the Change All.. button.
4. Run your scripts in a terminal window using python3.0 from the shell
command line. You can use the above path to execute python; it might
help to create a shell alias for it. Or double-click on the Update
Shell Profile command in /Applications/Python 3.0 to cause python3.0 to
be added to your shell PATH and then just type python3.0.
I would recommend either (or both) of the last two approaches. You'll
be better off avoiding Python Launcher.
--
Ned Deily,
nad at acm.org
More information about the Python-list
mailing list