Search code examples
pythonmacostensorflowinstallation

Make virtualenv with specific Python version (MacOS)


I installed brew, python3 (default and latest version) and pip3, pyenv.

TensorFlow does not support python3.7 now, so I heard that I should make a virtualenv that runs 3.6 or lower version independently.

I installed python 3.6.7 by pyenv install 3.6.7 but can't make virtualenv -p 3.6.7 (mydir) because 3.6.7 is not in the PATH (usr/local/bin).

How can I update my PATH?


Solution

  • You don't need the executable to be on the PATH. Assuming you want /usr/local/bin/python3.6.7 to be used in the virtual environment,

    virtualenv -p /usr/local/bin/python3.6.7 mydir
    

    With pyenv specifically, you could also do

    /Users/you/.pyenv/versions/3.6.7/bin/python -m venv mydir
    

    Updating your PATH is easy:

    PATH=/usr/local/bin:$PATH
    

    This will only update it in your current session; you might want to add this to your shell's startup files to make it permanent. This is a common FAQ but depends on a number of factors (your shell, etc) so google for details. Here is one question with several popular variants in the answers: Setting PATH environment variable in OSX permanently