Multiple versions of Python on OS X Leopard

泪湿孤枕 提交于 2019-11-26 11:03:30

问题


I currently have multiple versions of Python installed on my Mac, the one that came with it, a version I downloaded recently from python.org, an older version used to run Zope locally and another version that Appengine is using. It\'s kind of a mess. Any recommendations of using one version of python to rule them all? How would I go about deleted older versions and linking all of my apps to a single install. Any Mac specific gotchas I should know about? Is this a dumb idea?


回答1:


There's nothing inherently wrong with having multiple versions of Python around. Sometimes it's a necessity when using applications with version dependencies. Probably the biggest issue is dealing with site-package dependencies which may vary from app to app. Tools like virtualenv can help there. One thing you should not do is attempt to remove the Apple-supplied Python in /System/Library/Frameworks and linked to from /usr/bin/python. (Note the recent discussion of multiple versions here.)




回答2:


Ian Bicking's virtualenv allows me to have isolated Pythons for each application I build, and lets me decide whether or not to include the global site-packages in the isolated Python environment.

I haven't tried it with Zope, but I'm guessing that the following should work nicely:

  1. Using your Zope's Python, make a new virtualenv, either with or without --no-site-packages
  2. Drop your Zope into the virtualenv
  3. Activate the environment with $VENV/bin/activate
  4. Install any needed site-packages
  5. Run your Zope using the Python now at $VENV/bin/python

This has worked brilliantly for managing Django projects with various versions of Python, Django, and add-ons.

This article seems to go into more detail on the specifics of Grok and Virtualenv, but the generalities should apply to Zope as welll.




回答3:


+1 for virtualenv.

Even if you don't need different Python versions, it's still good to keep your development dependencies seperate from your system Python.

I'm not sure what OS you are using, but I find these instructions very useful for getting python development environments running on OSX.




回答4:


The approach I prefer which should work on every UNIX-like operating system:

Create for each application which need an specific python version an user account. Install in each user count the corresponding python version with an user-local prefix (like ~/build/python) and add ~/build/bin/ to the PATH environment variable of the user. Install/use your python applications in their correct user.

The advantage of this approach is the perfect isolation between the individual python installations and relatively convenient selection of the correct python environment (just su to the appropriate user). Also the operating system remains untouched.



来源:https://stackoverflow.com/questions/1218891/multiple-versions-of-python-on-os-x-leopard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!