pythonmacosinstallationversionsvirtual-environment

With Python 2.7.15 on a MAC console, virtualenv creates an environment with a different version of Python


Here is an extract of my console in a Mac, as you can see the Python on the console is 2.7.15 but on the environment it becomes 2.7.10 which is an older version... any help on why and how to fix it would be most welcomed!

dhcp-18-57:Wakeup6 **jbs$ python**  
**Python 2.7.15** (default, May  1 2018, 16:44:14)  
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin  
Type "help", "copyright", "credits" or "license" for more information.  
>>> exit()  

dhcp-18-57:Wakeup6 jbs$ virtualenv env  
New python executable in /Users/jbs/PycharmProjects/Wakeup6/env/bin/python  
Installing setuptools, pip, wheel...done.  

dhcp-18-57:Wakeup6 jbs$ source env/bin/activate  

(env) dhcp-18-57:Wakeup6 **jbs$ python**  
**Python 2.7.10** (default, Oct 23 2015, 19:19:21)  
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin  
Type "help", "copyright", "credits" or "license" for more information.  
>>> exit()

Solution

  • Thank you all for your input. I finally figured out how to solve it. The difficult part was finding out how to locate the place where python 2.7.15 was installed which I'll leave intact in the response since I found it by trial and error looking in other places. I have not found a command that gives you the full path (perhaps an expert can tell us how to go from the laconic which python to the full path).

    What I find interesting is that it does not really matter what the console uses when calling virtualenv. What matters is the version of Python used to install virtualenv which is the default version that will be used.

    Essentially one has to use the -p option in virtualenv and make sure to find the right location where the desired version of python is.

    dhcp-18--41:WakeUp8 jbs$ virtualenv -p /usr/local/Cellar/python@2/2.7.15/bin/python env
    Running virtualenv with interpreter /usr/local/Cellar/python@2/2.7.15/bin/python
    New python executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python2.7
    Also creating executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python
    Installing setuptools, pip, wheel...done.
    dhcp-18-189-34-41:WakeUp8 jbs$ python
    Python 2.7.15 (default, May  1 2018, 16:44:14) 
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> exit()
    
    dhcp-18--41:WakeUp8 jbs$ pwd
    /Users/jbs/PycharmProjects/WakeUp8
    
    dhcp-18-189-34-41:WakeUp8 jbs$ source env/bin/activate
    
    (env) dhcp-18-189-34-41:WakeUp8 jbs$ python
    Python 2.7.15 (default, May  1 2018, 16:44:14) 
    [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>>