Reputation: 131
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
Upvotes: 11
Views: 24712
Reputation: 75
Having had the same question in mind and after searching and seeking advice, I've found the following insights:
Reasons for separate commands:
Compatibility: Python 2 and 3 differ significantly. Mixing packages can cause errors. Separate commands prevent conflicts.
Clarity: Explicitly using pip3 indicates your intention to work with Python 3, especially when both versions are present.
Therefore, for all newly project we need to run
pip3 install virtualenv
Upvotes: 0
Reputation: 2054
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.
Upvotes: 8
Reputation: 2845
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
Upvotes: 4
Reputation: 408
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.
Upvotes: 2