Managing multiple Python versions on OSX

时间秒杀一切 提交于 2019-12-22 01:20:56

问题


What's the best way to manage multiple Python installations (long-term) if I've already installed Python 3 via brew? In the past Python versions were installed here, there, and everywhere, because I used different tools to install various updates. As you can imagine, this eventually became a problem.

I once was in a situation where a package used in one of my projects only worked with Python 3.4, but I had recently updated to 3.6. My code no longer ran, and I had to scour the system for Python 3.4 to actually fire up the project. It was a huge PITA.

I recently wiped my computer and would like to avoid some of my past mistakes. Perhaps this is naïve, but I'd like to limit version installation to brew. (Unless that's non-sensical — I'm open to other suggestions!) Furthermore, I'd like to know how to resolve my past version management woes (i.e. situations like the one above). I've heard of pyenv, but would that conflict with brew?

Thanks!


回答1:


Use virtualenvs to reduce package clash between independent projects. After activating the venv use pip to install packages. This way each project has an independent view of the package space.

I use brew to install both Python 2.7 and 3.6. The venv utility from each of these will build a 2 or 3 venv respectively.

I also have pyenv installed from brew which I use if I want a specific version that is not the latest in brew. After activating a specific version in a directory, I will then create a venv and use this to manage the package isolation.

I can't really say what is best. Let's see what other folks say.




回答2:


I agree to using virtualenv, it allows you to manage different python versions separately for different projects and clients. This basically allows you to have each project it's own dependencies which are isolated from others.



来源:https://stackoverflow.com/questions/47082736/managing-multiple-python-versions-on-osx

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