Como faço para o OS X Server 5.0 Use o Python 3.5?

1

O El Capitan e o OS X Server 5.0 usam o Python 2.7 por padrão. Eu instalei o Python 3.5, mas como faço o OS X Server 5.0 usá-lo para o wsgi sem quebrar a dependência do El Capitan no Python 2.7?

Basicamente, quero que o Mac OS X Server 5.0 use o Python 3.5 em vez do Python 2.7.

    
por Justin 10.11.2015 / 01:25

1 resposta

0

Uma resposta (aceita) é fornecida nos fóruns de suporte da Apple: link

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

Por favor, note que há muitas maneiras de instalar o pacote virtualenv . Eu usaria pip:

pip install virtualenv
O

pip vem com o Python 2.7.9 e posterior, e que também pode ser usado para adicionar mais pacotes ao seu virtualenvs. Se você não tiver o pip , poderá instalá-lo facilmente:

curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py
python get-pip.py
    
por 06.01.2016 / 12:56