We help IT Professionals succeed at work.

Python Apache Mod_Python problem

ssdesign
ssdesign asked
on
893 Views
Last Modified: 2013-11-08
Hi,
I have a problem understanding how the Python installations on my Macbook are working.

When I run Python programs from Terminal window, they are using this Python:
/Library/Python/2.6/

When I type "which python" it shows:
/usr/bin/python

When I run Python scripts in browser (.py scripts) the errors show that Apache is trying to use this python:
/Applications/MAMP/python/framework/Python.framework/Versions/2.6/lib/python2.6/

By the above, you would have realised that I have MAMP installed.
I have also installed SPMPT on top of MAMP (this installs the mod_python for MAMP and also comes with its own python)

So, my question is, whats going on here? and How can I easily tell Apache which Python to use while executing Python scripts in browser and visa versa, how can I configure Terminal and tell it to use a specific Python installation on my computer.

My ideal solution would be, terminal start using the same python that my Apache is using.

Looking forward to your answers.
Comment
Watch Question

Commented:
Hi,

I believe /usr/bin/python is just a stub program that reads the environment and other settings and then invokes the correct "real" python executable. I'm not sure how you determined that the python running in your terminal window was "/Library/Python/2.6/"

If you look in /usr/bin, you will see all these are links into the

$ ls -l python*
-rwxr-xr-x  2 root  wheel  86000 Feb 11 03:58 python
-rwxr-xr-x  5 root  wheel    925 Feb 11 18:55 python-config
lrwxr-xr-x  1 root  wheel     75 Apr 22 21:13 python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x  1 root  wheel     82 Apr 22 21:13 python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x  1 root  wheel     75 Apr 22 21:13 python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x  1 root  wheel     82 Apr 22 21:13 python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
-rwxr-xr-x  2 root  wheel  86000 Feb 11 03:58 pythonw
lrwxr-xr-x  1 root  wheel     76 Apr 22 21:13 pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x  1 root  wheel     76 Apr 22 21:13 pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6

 I'm not sure how you determined that the python running in your  terminal window was "/Library/Python/2.6/".  If you dig into this directory you find that it is a location for installing 3rd-party packages.  The README (e.g. /Library/Python/2.6/site-packages/README) says:

This directory exists so that 3rd party packages can be installed
here.  Read the source for site.py for more details.

Your MAMP package is invoking its own copy of python; a lot of self-contained frameworks will do this because they don't trust that the system version of python will be the correct version or will work properly.

Note that the man page for python gives a number of methods for changing the "default" python that is invoked.  Which one you use probably depends on how easily you want to be able to switch back and forth between python versions.  Here is that section:

CHANGING THE DEFAULT PYTHON
     Using

           % defaults write com.apple.versioner.python Version 2.5

     will make version 2.5 the user default when running the both the python and pythonw commands
     (versioner is the internal name of the version-selection software used).

     To set a system-wide default, replace `com.apple.versioner.python' with
     `/Library/Preferences/com.apple.versioner.python' (admin privileges will be required).

     The environment variable VERSIONER_PYTHON_VERSION can also be used to set the python and
     pythonw version:

           % export VERSIONER_PYTHON_VERSION=2.5 # Bourne-like shells
                or
           % setenv VERSIONER_PYTHON_VERSION 2.5 # C-like shells
           % python ...

     This environment variable takes precedence over the preference file settings.


Hope that helps.



Author

Commented:
very nice reply. this gives me more clarity and helps me articulate my problem better.

After reading all that you said, I would like to now phrase my questions this way:

I want to install a third party module which I would eventually want to use from a web browser.
So, currently when I run the setup script for that module, it installs it under: /Library/Python/2.6

So how can i install third party modules into my MAMP copy of Python?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Havent solved my problem but the user gave me good tips which I can now try to resolve my problem.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.