11

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

andres
  • 131
  • 1
  • 1
  • 5

3 Answers3

7

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.

Douglas Denhartog
  • 2,036
  • 1
  • 16
  • 23
  • so I did both `pip install virtualenv` and `pip3 install virtualenv` but there seems to be only one `virtualenv` so how can I know if that virtualenv is the one created by pip or pip3 – andres Feb 09 '14 at 20:42
  • 2
    No. What version your virtual environment will have is specified as argument, when actually making the env, like: `virtualenv -p python3 my_venv` or `virtualenv -p python2 my_venv`, regardless how the virtualenv package was installed. Furthermore checkout this: https://meta.stackoverflow.com/questions/361190/do-we-need-pip-and-pip3 – stelios May 20 '18 at 20:56
  • How to activate the virtualenv https://virtualenv.pypa.io/en/latest/user_guide.html#activators - `source bin/activate` – f01 Aug 26 '20 at 20:28
4
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

stelios
  • 2,679
  • 5
  • 31
  • 41
2

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.

TomKivy
  • 398
  • 2
  • 9