pythonvirtualenvhomebrewmultiple-versions

python: Understanding multiple versions, symlinks, and virtualenv


I need help understanding the organization of Python versions on my MacOS 10.12. I have both pip and brew, and no conda. Before I was working with Python 3.6.5, but then brew updated and installed Python 3.7.0.

Then I got the following problem while trying to create a new virtual environment:

$ virtualenv venv_pointnet
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python3/bin/python3.6: bad interpreter: No such file or directory

So then I added this line to my ~/.bash_profile:

alias python3="/usr/local/Cellar/python/3.6.5/bin/python3.6"

But the problem still persists....

Here is some Python info on my system.

$ head -1 $(which virtualenv)
#!/usr/local/opt/python3/bin/python3.6

$ python3 --version
Python 3.6.5

$ which -a python3
/usr/local/bin/python3 

$ ls -l /usr/local/bin/python3
lrwxr-xr-x  1 myUser  admin  34 Oct 28 21:51 /usr/local/bin/python3 -> ../Cellar/python/3.7.0/bin/python3

$ ls -l /usr/local/opt/python3
lrwxr-xr-x  1 myUser  admin  22 Oct 28 21:51 /usr/local/opt/python3 -> ../Cellar/python/3.7.0

My questions

  1. Why does there seem to be multiple python3s, but $which -a python3 only returns one directory?

  2. If my current python3 version is 3.6.5 thanks to the alias, then why is there still a symlink to 3.7.0 ?

  3. How can I make my virtualenv work? Can its interpreter still remain 3.6.5 or must I change it to 3.7.0?

  4. What other things might the brew update have 'broken' in regards to python versions and symlinks?

I know the questions are broad, but anything to help me get a better understanding of this python environment stuff, I would greatly appreciate! Besides programming in the python language, I don't much else about its setup >.<


Solution

  • 1

    Because /usr/local/bin/python3 is a symlink to one particular version

    2

    You created an alias, but that doesn't actually change the symlink of /usr/local/bin/python3. If you really want to make use of version 3.6.5, though, you could do something like this:

    rm /usr/bin/python3
    ln -s /usr/bin/python3.6 /usr/bin/python3
    

    which creates the corresponding symlink

    3

    I don't believe you can change the version of python of the virtualenv. You might want to try to reinstall it

    4

    ¯\_(ツ)_/¯