Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtualenv - Python 3 - Ubuntu 14.04 64 bit

I am trying to install virtualenv for Python 3 on Ubuntu 64bit 14.04.

I have installed pip for Python3 using:

pip3 install virtualenv 

and everything works fine. Now though I am trying to use virtualenv command to actually create the environment and getting the error that it is not install (i guess because I haven't installed it for Python 2 and that is what it is trying to use)

How do I use the virtualenv for Python 3? I have searched the documentation but can't see where it says what to do.

like image 447
timbram Avatar asked Apr 29 '15 03:04

timbram


People also ask

Does Python 3.10 have venv?

Creating a Python Virtual Environment virtualenv supports older Python versions and needs to be installed using the pip command. In contrast, venv is only used with Python 3.3 or higher and is included in the Python standard library, requiring no installation.

Does virtualenv work with Python 3?

Virtualenv is only installed on DreamHost servers for Python 2. If you're working with Python 3, you must install virtualenv using pip3. pip3 is not installed on the server by default. You must first install a custom version of Python 3.


1 Answers

I had the same issue coming from development environments on OS X where I could create Python 3 virtual environments by simply invoking virtualenv and the path to the target directory. You should be able to create a Python 3.x virtual environment in one of two ways:

  1. Install virtualenv from the PyPi as you've done ($ pip3 install virtualenv), then by calling it as a module from the command line:

    $ python3 -m virtualenv /path/to/directory

  2. Use the venv module, which you can install through apt-get. (Note that Python 3.3 is when this module was introduced, so this answer assumes you're working with at least that):

    $ sudo apt-get install python3.4-venv

    Then you can set up your virtual environment with

    $ pyvenv-3.4 /path/to/directory

    and activate the environment with

    $ source /path/to/directory/bin/activate

You might also look at this post, which discusses differences between the venv module and virtualenv. Best of luck!

like image 75
Celaxodon Avatar answered Sep 27 '22 19:09

Celaxodon