Franck Dernoncourt
Franck Dernoncourt

Reputation: 83427

How can I create a virtual environment with virtualenv for Python 3.7 without having to install Python 3.7 on my computer (Ubuntu 16.04.6 LTS x64)?

How can I create a virtual environment with virtualenv for Python 3.7 without having to install Python 3.7 on my computer (Ubuntu 16.04.6 LTS x64)?

virtualenv -p python3.7 /mnt/ilcompn0d1/user/dernonco/pyenv/codetest

yields:

The executable python3.7 (from --python=python3.7) does not exist

but I would prefer not to have to install Python 3.7 on my computer.

Upvotes: 0

Views: 4241

Answers (1)

Chris
Chris

Reputation: 137182

You don't need to install Python 3.7 system-wide, but you do need to install it somewhere if you want to use it in a virtualenv. Easy options include via pyenv or pythonz.

If you install pyenv, install Python 3.7 via pyenv install 3.7, then create your virtualenv. Or use a higher-level tool like Pipenv, which can manage virtualenvs for you and install them via pyenv automatically:

  1. Install pyenv
  2. Install pipenv, e.g. with pip install --user pipenv
  3. In a project directory, create new virtualenv using pipenv:

    pipenv install --python 3.7
    

    Python 3.7 will automatically be installed for your user via pyenv.

Alternatively, pew can do much the same thing via pythonz:

  1. Install pew with the optional pythonz integration:

    pip install --user pew[pythonz]
    
  2. Create a new virtualenv:

    pew new -p $(pythonz locate 3.7) some-name
    

Both of these solutions assume that you have the Python user directory added to your $PATH. On my system that's ~/.local/bin/. Use import site; print(site.USER_BASE) to double-check on your machine.

Upvotes: 2

Related Questions