-3

On my osx machine I have python 2.7.15 running.

When I run virtualenv, activate the env, and check the python version, i get 2.7.10.

$> virtualenv env

Unfortunately, I really need version 2.7.15. I tried to specify the virtualenv version by adding the path to /usr/bin/python2.7, but it still creates an env using python 2.7.10.

Any idea how I can set up the version more specifically ?

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

SOLVED:

This question solves it but maybe the phrasing of the question was too specific. It solved my issue though. With Python 2.7.15 on a MAC console, virtualenv creates an environment with a different version of Python

Maybe keep this one open for more visibility? It's not about choosing the version, it's about finding where the sub-version (e.g., 2.7.10 or 2.7.15, etc.) is located on the machine. Obviously passing the python interpreter as command line was tried before posting to Stack Overflow.

vancy-pants
  • 1,070
  • 12
  • 13
Arro
  • 158
  • 1
  • 10
  • 1
    Can you show the exact command you use to create the virtualenv? – smac89 Jan 25 '19 at 16:12
  • I recommend using [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/install.html) – smac89 Jan 25 '19 at 16:16
  • Did you install python using Anaconda? if so when you create the virtual environment, specify the complete name of the version you want to use. For example "conda create -n yourenvname python=x.x anaconda" . the x.x should be 2.7.15 – Natsfan Jan 25 '19 at 16:23

3 Answers3

1

You can try pyenv, where you can install as many Python versions as you want. First you need to install Homebrew:

$ brew update
$ brew install pyenv, pyenv-virtualenv
$ pyenv install 2.7.15
$ pyenv virtualenv 2.7.15 my-virtualenv
$ pyenv activate my-virtualenv
Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73
0

The trick is that virtualenv uses the python version used to install virtualenv, not the one currently running. Therefore its a matter of finding the right version on your machine.

The python subversion can be located here:

/usr/local/Cellar/python@2/2.7.15/bin/python

You can therefore create virtualenv like this

virtualenv -p /usr/local/Cellar/python@2/2.7.15/bin/python

Arro
  • 158
  • 1
  • 10
0

When you define your virtual environment you should attach a version of python to that environment. See my comment above if you are using anaconda. So when you create your virtual environment be sure to put the exact version of python. For example use 2.7.15 instead of 2.7

Natsfan
  • 4,093
  • 3
  • 22
  • 29