1

El Capitan and OS X Server 5.0 use Python 2.7 by default. I've installed Python 3.5, but how do I make OS X Server 5.0 use it for wsgi without breaking El Capitan's dependence on Python 2.7?

Basically, I want Mac OS X Server 5.0 to use Python 3.5 instead of Python 2.7.

Justin
  • 11
  • 1

1 Answers1

0

An (accepted) answer is provided in the Apple Support Forums: https://discussions.apple.com/thread/7331263?start=0&tstart=0

I have not had to do this with the current Server 5.0 but have done it previously with Server 4.x (I now use Linux Virtual machines for this sort of purpose but the solution is exactly the same as you need for OS X Server.)

First absolutely do not try updating the built-in components of any Apple included software e.g. Apache, and in your case Python. While it may be possible to do this, not only are Apple making such steps harder to do by adding new security measures to prevent their 'official' software being modified/hacked without your knowledge, trying this approach makes it extremely likely you will break something especially the integration between Server.app and these components and also make it likely that installing future official Apple updates will either fail or downgrade what you did anyway.

So, as I implied above I have used a solution before which works, and does not cause the problems described above - at least with regards to Python. The approach you need to adopt is to leave Apple's Python well alone and instead install a separate copy specifically to be used with your own website, indeed if you were to run multiple websites - each needing to use Python you would have separate copies of Python for each site because it is quite common for various Python based projects to be dependent on specific Python versions. So common is this that there is a tool specifically for doing this called VirtualEnv.

See http://docs.python-guide.org/en/latest/dev/virtualenvs/

The way this works is -

  • You install VirtualEnv
  • You run VirtualEnv and create a virtual environment for your website
  • You install the specific Python version you need for your website in to that virtual environment
  • You install all the Python modules you need for your website in to that virtual environment
  • You install your Python code in to that virtual environment

Then you have appropriate entries in your website conf file to run within that virtual environment.

By adopting this approach it is then possible to simultaneously run multiple different versions of Python and not have them conflict with each other.

Note: To install VirtualEnv in OS X do the following.

sudo easy_install virtualenv

Please note that there are many ways you can install the virtualenv package. I would use pip:

pip install virtualenv

pip comes with Python 2.7.9 and later, and which can also be used to add more packages to your virtualenvs. If you do not have pip, you can install it easily:

curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
python get-pip.py
fredrik
  • 731
  • 15
  • 20