Ask HN: People using both python 2.x and 3.x on OS X, what setup do you use?
Specifically I'm wondering how you make it all work with installing and using modules, when a few things are happening:
- You may need to run 2.7 scripts
- You may need to run 3.x scripts
- You may need to edit, create, and maintain scripts of both versions.
- The system may change the system python out from under you, with major updates of the OS or Xcode
- You install libraries with pip or pip3 and they claim to have installed for a specific version of python, but then at run time, that same specific version of python complains that the library isn't installed.
What setup is best for managing this?
If your answer is "I don't do that" or "I wouldn't do that if I were you" then it's OK, you don't have to answer... this question is for people who are doing it.
4 comments
[ 2.3 ms ] story [ 22.2 ms ] threadMy setup: 1) never use the system Python for development. 2) install Python 2.7.10 and 3.4.3 from mac ports. 3) Always work in a virtual environment. 4) When developing generic scripts, use the port select method to switch between versions. 5) Have virtual environments built out for both versions.
What I've not yet done is write a script to build a binary 2.7 and 3.4 wheel. In that case, I'd likely just refer to the 2.7 and 3.4 versions specifically instead of generically (ie. python2.7 and python3.4 vs. just python).
I installed both versions of Python using homebrew[0] so it doesn't matter which version OS X ships with.
Python 2 is still the default. So I have python and pip, and then python3 and pip3.
Every project I work on has a virtual environment[1], which is named after the owner and the project, e.g. citruspi-skynet.
If it's a Python 2 project, I just create the virtual environment normally.
If it's a Python 3 project, I set the location of Python interpreter. I've run into situations where I have to port a Python 2 project to Python 3, while maintaining the Python 2 project. In that case, I normally use the same repository, but a new branch. However, I'll keep two copies of the repository locally so I can work on both branches at the same time. And then I'll have two virtual environments, citruspi-skynet and citruspi-skynet3.I haven't run into any issues with this setup and I've been pretty happy.
[0]: http://brew.sh
[1]: https://virtualenv.pypa.io/en/latest/