Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

install virtualenv using pip or pip3?

Tags:

pip

homebrew

I used brew to install both python2 and python3

brew install python
brew install python3

I noticed that there are pip and pip3 so which pip should I use to create virtualenv

pip install virtualenv or pip3 install virtualenv

like image 630
andres Avatar asked Feb 09 '14 19:02

andres


Video Answer


3 Answers

Use pip install virtualenv to create a python env and pip3 install virtualenv to install a python3 env

The difference is required because if you use pip install virtualenv and need python3 packages, you will get all kinds of errors!

UPDATE (2020-03-12): With python3 you can also use

python3 -m venv {directory}

where {directory} is the path of/to your virtualenv.

like image 196
Douglas Denhartog Avatar answered Oct 13 '22 01:10

Douglas Denhartog


pip install virtualenv

This doesn't create any virtual environment. That installs virtualenv program, that is used in order to create virtual environments.

What is the default python version that your virtual environment will have is specified as an argument, when actually making the env, like:

virtualenv -p python3 my_venv 

or

virtualenv -p python2 my_venv

regardless on how the virtualenv package was installed.

Furthermore checkout this

like image 45
stelios Avatar answered Oct 13 '22 00:10

stelios


Your second question:"how can I know if that virtualenv is the one created by pip or pip3?"

-> You can activate the virtual environment with source bin/activate(first cd in the folder of the environment) When you are sure you are in the virtual environment, type "python --version". You can also check which python is active in the environment by typing "which python". Hope this helps.

like image 37
TomKivy Avatar answered Oct 12 '22 23:10

TomKivy