Search code examples
pythonpython-3.xpython-2.7virtualenvvirtualenvwrapper

Python: Install VirtualEnv for both Python 2 and Python 3


After moving over to Fedora (from Windows), I realized that it came with both installations of Python 2.7.5 and Python 3.6.6.

As I familiarized myself with using Python, I learned of the great utilities of virtual environments and how organized they keep everything.

However, my current dilemma is for which Python version should I do pip(2 or 3) install virtualenv virtualenvwrapper.

From my research, I understand that the virtualenvwrapper provides the ability to create a virtual environment using a specified version of Python: mkvirtualenv -p /usr/bin/python(2 or 3) {name}.

Therefore, should I only install virtualenv and virtualenvwrapper on one of the Python versions and use the aforementioned feature? Or should I install virtualenv and virtualenvwrapper on both versions of Python.

Would there be any conflicts?

Edit

More importantly, assuming that I have virtualenv and virtualenvwrapper installed for both Python 2.7.5 and Python 3.6.6, which version's command is called when I run any of the following: workon, mkvirtualenv, rmvirtualenv, etc.?


Solution

  • Would there be any conflicts?

    Not until you mistakenly run the default system python command with a script that's using the opposite version as compared to the more specific python2 or python3 commands.

    The virtualenvs do not conflict, and must be activated to be used. You can also of course have as many virtualenv's as you wish.

    To avoid any problems setting up an environment, its suggested to run python2 -m virtualenv for example, rather than simply virtualenv command itself

    For the commands listed at the bottom of the question, it depends on how your PATH is configured. Personally, I use pyenv rather than virtualenv directly, which injects itself into the OS PATH variable