Python automatically smoothes on Mac OS X Lion

I struggled with installing Python 2.7 as the default Python on my system.

Python 2.6 came from my OS, and since then I installed 2.7 (from the source) and tried to make this version the default one.

At some point, I was offered to try the package manager (MacPorts / Fink / Homebrew), and I thought it was a bad idea.

A common problem is that somewhere, Python 2.6 gets automatically smoothed like my python by default every time my shell starts. I went through my .profile and .bashrc, and there are no commands that could use them.

I also set my default path to take a look at /Library/Frameworks/Python.framework/Versions/2.7/bin . I also tried the sentences in this SO post and this SU post to no avail. I need to use 2.7 as my default value because I have argparse dependent scripts etc.

In addition, my / usr / bin / python is not an alias to anything, but / usr / local / bin: /usr/local/bin/python -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python

+6
source share
1 answer

I struggled with installing Python 2.7 as the default Python on my system.

It happened before. When you take the clear Lion flag and enter python into the shell, it runs /usr/bin/python , which is Python 2.7.2.

Python 2.6 came from my OS

The lion comes with 2.5, 2.6 and 2.7 and hidden 2.3.

They are installed in /System/Library/Frameworks/Python.framework/Versions . All but 2.3 have symbolic links /usr/bin/python2.x , which on a clean system will be the first in your PATH with that name, so just type python2.6 by running 2.6 and python2.7 will run 2.7.

There is also a special shell in /usr/bin/python that starts 2.7 by default, but you can configure it using VERSIONER_PYTHON_VERSION or com.apple.versioner.python .

Since then I installed 2.7 (from source) and tried to make this version the default.

What do you mean by default version? Do you just want this to be executed when you inject python into a new terminal shell or use #!/usr/bin/env python as the shebang string in a script?

The easiest way to do this is to get any directory that you set it higher in PATH than / usr / bin.

If you set the "frame assembly" (which you should have), the /Library/Frameworks/Python.framework/Versions/2.7/bin directory will appear, which you can place at the top of your PATH. This allows you to not affect the order of / usr / local and / usr, and this means that you can use any scripts that are installed by the Python setup.py settings, without having to bind them to / usr / local / bin.

This is important because Apple Python will install scripts in / usr / local / bin - for example, if you are /usr/bin/easy_install-2.7 pip , you will get /usr/local/bin/pip and / usr / local / bin / pip -2.7 . If you also install . If you also install pip` for your custom Python, you do not want it to appear in the same place; otherwise, whichever you install, the latter replaces the other.

If you did not install the framework assembly or configure it to install scripts on /usr/local/bin , or want to influence the order of / usr / local, just put /usr/local/bin at the beginning of your PATH.

somehow, Python 2.6 gets auto-smoothing like my python by default every time my shell starts

By auto-smoothing, do you mean bash alias ? Like your alias type, and it gives you a list of things including python ?

If so, you need to fix it, and not try to build another hack on top of it in order to undo any effect that it has.

If there are no alias commands in ~/.* , look at /etc/ . If you grep -r alias /etc , this will give you a long list of things and you will have to skip the mail aliases and apache aliases (and maybe some permission rejected the output to stderr), but after that there should not be an alias shell.

Also, my / usr / bin / python is not an alias to anything,

It makes me think that you are misleading aliases and symbolic links. This is not the same thing. What is the problem? You must know what is wrong before you can fix it.

So try the following:

 which python 

It should be /Library/Frameworks/Python.framework/Versions/2.7/bin/python if your PATH is what you say. If not, you do not configure your PATH correctly, so echo $PATH and see.

If so, then ls -l /Library/Frameworks/Python.framework/Versions/2.7/bin/python . It should be a symbolic link to python2.7 or ./python2.7 , and not to anything in another directory. If not, your installation will fail, and it is best to uninstall Python and install it correctly. Or just do not reinstall it and do not use Apple. Either if you really need 2.7.3 instead of 2.7.2, or you need to create stand- py2app packages (especially if you need to be compatible with the old OS X), or you are allergic to sudo and prefer the files of the whole system were available to the whole world or for any other reason you cannot use Apple, install from python.org or Homebrew, and not try to do it yourself.

+5
source

All Articles