2

I recently upgraded Python (via downloaded .dmg files). Before, my $PATH looked like this:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Now when I run the command:

$ echo $PATH | tr ':' '\n'

the following two lines are added:

/Library/Frameworks/Python.framework/Versions/2.7/bin
/Library/Frameworks/Python.framework/Versions/3.4/bin

I've noticed that my ~/.bash_profile has only the following content:

# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

So, if the original versions are saved in their respective, python-specific .bash profiles, can I delete this content from my ~/.bash_profile?

Why would these duplicates be added to ~/.bash_profile in the first place?

3
  • What shell are you using - echo $PATH in bash shows one line the components are separated by : not new line
    – mmmmmm
    Feb 17, 2015 at 23:14
  • Apologies for not mentioning, but for the sake of asking my question here, I ran the command: $ echo $PATH | tr ':' '\n' just to separate out the file paths before copying them into my post
    – g3V
    Feb 18, 2015 at 9:54
  • I am using the default, bash shell on OSX.
    – g3V
    Feb 18, 2015 at 9:57

1 Answer 1

1

Unless the new items are causing trouble, I suggest leaving them as-is. Most apps will probably have their desired version of Python bundled with them, but some may not, and some may want the 2.7 framework rather than the 3.4 version. The only issue I can think of is if Python 3.4 is running and accidentally stumbles over the 2.7 files first because they are first in the PATH.

As for where they're coming from, they're coming from your .bash_profile. The lines you pasted from there show the two directories being prepended to the PATH environment variable. Since they don't get added twice, the Python installation edited your .bash_profile directly. Removing them will, no doubt, remove them from PATH, with questionable benefit.

Finally, I would not recommend uninstalling both versions of Python. Keep at least the one that came with your OS. You might have some better control using MacPorts to install updated versions of Python, if you really need them. Again, you don't say if there's any real problem other than things looking funny, so it's hard to make recommendations.

4
  • The two new lines are added since upgrading Python.
    – g3V
    Feb 17, 2015 at 22:12
  • There is no problem that I'm aware of.
    – g3V
    Feb 20, 2015 at 19:02
  • 1
    As Joe touched on, it makes no sense to have two versions of Python loaded in your path successively. The first one declared will always win over the other one, which means that if you run python --version in your command line you will always see 3.4 and never 2.7. You can, however, invoke the python binary manually. An easy way to do that is the which -a python trick which will show you all the versions of the python binary loaded in your path. You can then execute the one you want with its absolute path. Example: /Library/Frameworks/Python.framework/Versions/3.4/bin --version Feb 21, 2015 at 2:30
  • The only reason it might make sense, @OlivierLacan, is if Python uses GNU standard versioning for its libraries. A program looking for libpython.so.3.4.0 (just making that up for discussion) could find the right one with both in the path, as could one looking for libpython.so.2.7.0.
    – Joe Sewell
    Feb 23, 2015 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .