Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

danqi

macrumors regular
Original poster
Sep 14, 2010
233
19
I am using Sierra right now but will be moving over to a new Mac soon.

Many years ago I learned some basic programming (bash and python) and wrote a few little scripts that I still use a lot for work.

I have since forgotten most of what I had learned, though.

I read somewhere that the version of python I had used is now outdated. I think it was 2.7 (can that be right?).

Will I be able to use my scripts on the new Mac? If not, what would I need to do to get them running?
 
I am using Sierra right now but will be moving over to a new Mac soon.

Many years ago I learned some basic programming (bash and python) and wrote a few little scripts that I still use a lot for work.

I have since forgotten most of what I had learned, though.

I read somewhere that the version of python I had used is now outdated. I think it was 2.7 (can that be right?).

Will I be able to use my scripts on the new Mac? If not, what would I need to do to get them running?
Python 3 was a big departure from Python 2 in many ways, and the majority of Python 2 code will not run with Python 3. However, you can still run Python 2 on new Macs no problem and while it's recommended to move to Python 3, I believe 2 still gets minor updates for bug fixes but not feature updates. - Though that is probably not going to last too much longer.
Python 2 is end of life as per chrfr. Doesn't get any form of updates any longer. It did for years after Python 3, but no more :)

I believe Python 2 still comes bundled with Xcode but if not you can definitely get it with homebrew. You can try running your scripts with Python 3 and see if they run - they most likely won't but you can then based on the error messages maybe fix them up, or alternatively just run them through Python 2 and all will be good :)
 
Last edited:
Oh, as for bash, the default shell is zsh now. If your scripts specify at the top that they use bash
like with:
#!/bin/bash
nothing will change for your bash scripts. If you just assumed the scripts were already running in a bash context and didn't include the interpreter specifier, things will most likely still work the same but some things may work differently under the zsh interpreter
 
Thanks for all the info!

I will try to fix my Python scripts or install Python 2 as a band-aid solution.

But going through all of my scripts I just noticed that my Bash scripts are significantly more important for my workflow. So it's good to hear that they will work. They even all include the "#!/bin/bash" at the top already.
 
Thanks for all the info!

I will try to fix my Python scripts or install Python 2 as a band-aid solution.

But going through all of my scripts I just noticed that my Bash scripts are significantly more important for my workflow. So it's good to hear that they will work. They even all include the "#!/bin/bash" at the top already.
Apple has deprecated bash so that will be going away at some point. zsh is the new default shell, so you may want to look at migrating your shell scripts over. Some may “just work” in zsh, but they may not all work without modification.
 
  • Like
Reactions: danqi
Apple has deprecated bash so that will be going away at some point. zsh is the new default shell, so you may want to look at migrating your shell scripts over. Some may “just work” in zsh, but they may not all work without modification.

While Apple may eventually remove bash from macOS' default installation one can always just install it. I typically do that anyway since Apple only ships bash 3.2.
 
While Apple may eventually remove bash from macOS' default installation one can always just install it. I typically do that anyway since Apple only ships bash 3.2.
Then of course all the scripts also need editing to point to the newly installed copy of bash. It’s probably a bit more resilient to use one of the shells that stay included in the OS, assuming nothing breaks badly. It’s too bad Apple can’t just keep including bash, and update it at least once every few years.
 
Then of course all the scripts also need editing to point to the newly installed copy of bash. It’s probably a bit more resilient to use one of the shells that stay included in the OS, assuming nothing breaks badly. It’s too bad Apple can’t just keep including bash, and update it at least once every few years.
Can just symlink the new bash into /bin/bash. But an alternative approach, sure they could all be updated - Can probably automate a find and replace pretty quickly. - But yeah redoing what may be different for zsh is also a valid approach
 
I will try to fix my Python scripts or install Python 2 as a band-aid solution.
Maybe it helps to have multiple Python versions installed for porting. Take a look at pyenv. With that you can run Python 2 and 3 in parallel without messing up your system.
 
  • Like
Reactions: danqi
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.