LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2009, 11:49 PM   #1
blueheron66
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Rep: Reputation: 0
bash: python: command not found


I am a new python user trying to get 3.0 to work on my computer. While trying to change the default version of python from 2.4.3 to 3.0, I followed the advice of another forum and changed typed

rm /usr/bin/python
into the console to remove the link to the old python.

I then entered
ln -s /usr/bin/python3.0 /usr/bin/python
but after doing so my computer no longer recognizes the "python" command.
Is there any way to fix this so that I can use python again?
 
Old 01-08-2009, 12:41 AM   #2
agrestic
Member
 
Registered: Jan 2009
Location: atlanta, ga, usa
Distribution: sabayon 5, slack64, Lenny, LFS 6.4 user # 20665
Posts: 61

Rep: Reputation: 16
Quote:
Originally Posted by blueheron66 View Post
I am a new python user trying to get 3.0 to work on my computer. While trying to change the default version of python from 2.4.3 to 3.0, I followed the advice of another forum and changed typed

rm /usr/bin/python
into the console to remove the link to the old python.

I then entered
ln -s /usr/bin/python3.0 /usr/bin/python
but after doing so my computer no longer recognizes the "python" command.
Is there any way to fix this so that I can use python again?
You removed /usr/bin/python (via the rm command), so you can't link python3 to a non-existent location. Here's 3 options:
1. Re-install python 2.x, download the python3 source and choose make fullinstall to overwrite the 2.x installation.
2. You can have multiple versions using make altinstall.
3. Try ipython.

From the python3.0 README:

Converting From Python 2.x to 3.0
---------------------------------

Python 2.6 contains features to help locating and updating code that needs to be changed when migrating to Python 3.

A source-to-source translation tool, "2to3", can take care of the
mundane task of converting large amounts of source code. It is not a
complete solution but is complemented by the deprecation warnings in
2.6. This tool is currently available via the Subversion sandbox:

http://svn.python.org/view/sandbox/trunk/2to3/


Installing multiple versions
----------------------------

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using "make altinstall" contain the major and minor version and can thus live side-by-side. "make install" also creates ${prefix}/bin/python which refers to ${prefix}/bin/pythonX.Y. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using "make install". Install all other versions using "make altinstall".

For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.
 
Old 01-08-2009, 07:35 AM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
blueheron66: can you verify with ls that /usr/bin/python -> /usr/bin/python3.0 ? Can you execute /usr/bin/python3.0 as a command by itself? Where there any errors when you made the link? It's hard to tell what could be wrong without some more information.

Quote:
Originally Posted by agrestic
You removed /usr/bin/python (via the rm command), so you can't link python3 to a non-existent location.
The arguments for ln are DEST SRC so `ln -s /usr/bin/python3.0 /usr/bin/python` will work just fine.
 
Old 01-08-2009, 08:00 AM   #4
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
Quote:
Originally Posted by taylor_venable View Post
The arguments for ln are DEST SRC so `ln -s /usr/bin/python3.0 /usr/bin/python` will work just fine.
I think you meant SRC DEST, but yes, the command should work. It won't give an error even when SRC is non-existent, and goes ahead and creates /usr/bin/python. ls -l /usr/bin/python* and which python3.0 would help see what went wrong here.
 
Old 01-08-2009, 09:52 AM   #5
acerimusdux
LQ Newbie
 
Registered: Aug 2004
Posts: 12

Rep: Reputation: 0
Quote:
Originally Posted by arungoodboy View Post
I think you meant SRC DEST, but yes, the command should work. It won't give an error even when SRC is non-existent, and goes ahead and creates /usr/bin/python. ls -l /usr/bin/python* and which python3.0 would help see what went wrong here.
Yes, I suspect python3.0 may not be installed in /usr/bin. I installed mine in /usr/local/bin, so that command would not have worked for me either.
 
Old 01-08-2009, 08:03 PM   #6
blueheron66
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Reinstalling python 3.0 doesn't seem to fix the problem. This is what ls -l /usr/bin/python* gives me

$ ls -l /usr/bin/python*
lrwxr-xr-x 1 root wheel 18 Jan 7 23:35 /usr/bin/python -> /usr/bin/python3.0
lrwxr-xr-x 1 root wheel 72 Apr 27 2006 /usr/bin/python2.3 -> ../../System/Library/Frameworks/Python.framework/Versions/2.3/bin/python
lrwxr-xr-x 1 root wheel 10 Apr 27 2006 /usr/bin/pythonw -> pythonw2.3
-rwxr-xr-x 1 root wheel 34216 Jan 13 2006 /usr/bin/pythonw2.3

/usr/bin/python is linked to /usr/bin/python3.0 but the command still does not work
when I try to create one again it responds that the file exists
 
Old 01-08-2009, 08:45 PM   #7
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Quote:
Originally Posted by arungoodboy View Post
I think you meant SRC DEST, but yes, the command should work.
No, I meant the link starts at SRC and points to DEST. [Not that it really matters.]

blueherron66: Looks like a Mac? From this listing, there is no /usr/bin/python3.0 for the link to go to. I'm not a Mac user, but perhaps /System/Library/Frameworks/Python.framework/Versions/3.0/bin/python exists and if it does you should also make a link from /usr/bin/python3.0 to point there. Basically the link means "when I use the SRC file, actually access the DEST file." So when you have /usr/bin/python -> /usr/bin/python3.0 that means access to /usr/bin/python actually go to /usr/bin/python3.0 (that's the explanation in a nutshell). Since /usr/bin/python3.0 does not exist for you, bash complains. You must create /usr/bin/python3.0, probably by following the link pattern which /usr/bin/python2.3 uses (notice how it points to /System/.../2.3/bin/python).
 
Old 01-08-2009, 08:47 PM   #8
rm_dash_rf_star
Member
 
Registered: Nov 2007
Location: Seattle, WA
Distribution: LFS
Posts: 36

Rep: Reputation: 16
Try running python3.0 explicitly:

/usr/bin/python3.0

It this works, and your shell still does not recognize the command `python', then it may have to do with shell hashing.

Basically, when you use a command, shells like BASH throw the name and location into a table so that it does not have to go find the binary next time that you use the program.

To verify that this is the case, turn off hashing:

$ /bin/bash +h


Then try running `python'
 
Old 01-08-2009, 09:21 PM   #9
blueheron66
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks so much for all the help so far. I looked in System/Library/Frameworks/Python.framework/Versions and it looks like 3.0 never installed corectly. All I have is 2.3 in that folder when I should have 3.0. It looks like I have some problems with installing python 3.0 to figure out before I try to change the default version.
When I tried to restore the link between /usr/bin/python and its counterpart, bash claims that /usr/bin/python does not exist, even though I can see plainly that it DOES indeed exist, as I have checked manually.

ln /usr/bin/python /System/Library/Frameworks/Python.framework/Versions/2.3/bin/python
ln: /usr/bin/python: No such file or directory
 
Old 01-08-2009, 09:57 PM   #10
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Quote:
Originally Posted by blueheron66 View Post
ln /usr/bin/python /System/Library/Frameworks/Python.framework/Versions/2.3/bin/python
ln: /usr/bin/python: No such file or directory
Oh noes! Don't do this as root. This command would make /System/Library/Frameworks/Python.framework/Versions/2.3/bin/python point to /usr/bin/python -- more than likely not what you want. The arguments for ln are the thing pointed to and then the thing which does the pointing. DEST then SRC. This is because the SRC is optional and when it is missing ln creates the last path component name of DEST in the current directory as the thing doing the pointing.

Last edited by taylor_venable; 01-08-2009 at 09:58 PM. Reason: cleaned up wording a bit
 
Old 01-08-2009, 10:21 PM   #11
blueheron66
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Oops... I fixed the ordering of that command and now i am prevented from creating that link because /usr/bin/python DOES exist. Sorry if these questions seem dumb; I'm not experienced with using the terminal or python.
 
Old 01-09-2009, 05:43 AM   #12
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
By default, ln won't overwrite something which already exists with a link (precisely to prevent such accidents) so you can either just rm /usr/bin/python first or use the -f option to force an overwrite. You probably want to use the -s option to specify a symbolic link as well.

The questions aren't dumb. I've been caught forgetting myself on the file order as well. You should read man ln to get a good impression of what a command does before running it though.

I don't know if you've already tried it, or are currently trying to use it, but there's apparently a special installer package for Python on Mac which you can use.
 
Old 01-09-2009, 03:16 PM   #13
blueheron66
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Original Poster
Rep: Reputation: 0
SUCCESS!!!1!1 At least now I'm back to square one. Thank you for your help and for informing me of the "man" command. Using "man" will help me help myself rather than burdening the internet with my console questions. It would seem that the link to installing a newer version of macpython on the python website leads only to framework based add-ons. I have installed a few of these and hope to take advantage of their features soon. The inpression that I'm getting from the python website is that the newest version of python that readily works for OSX 10.4 is 2.4. The makefile for versions newer than 2.4 has trouble making a couple modules that I'm currently trying to find and fix...but that's another story.
Thank you for your help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python script wont start - bash: myCommand : command not found owenm Linux - Newbie 2 11-06-2008 11:50 AM
bash command not found manolakis Linux - Newbie 13 01-21-2007 02:07 PM
bash: rpm: command not found && sudo: alien: command not found Java_Code Ubuntu 7 07-27-2006 11:57 PM
bash syntax when envoking tar command in python script tangle Programming 4 02-04-2006 03:22 PM
bash -command not found- K3V Linux - Newbie 7 09-30-2004 03:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration