Search code examples
pythonpython-3.xvirtualenvversiondefault

Change python version by default in virtualenv


I'm working with virtualenv in a project that was initialised with python2.7 and now i want to change the python version of my project with python3.5 by default! Can anyobody help me !!!


Solution

  • You can use this command:

    mkvirtualenv -p python3 env-name
    

    Detailed instruction to change your Python version:

    1. Deactivate your current environment session.
    2. If you have many packages or libraries installed, it would be a good idea to make a requirements.txt file. Remember to edit version as necessary.
    3. Remove the virtualenv with the wrapper command: rmvirtualenv

    This will remove the virtualenv, but leave your project files.

    1. Make a new virtualenv with the Python version you want.

    Example: mkvirtualenv -p python3 env-name

    You can specify the Python version with the -p flag and version. If you have a requirements.txt file, you can specify that with -r requirements.txt

    1. Now bind your new virtualenv to your project directory. You can specify the full paths, but it is easier to have your new virtualenv activated and be in your project directory. Then, run the command:

    Example: setvirtualenvproject

    The source is here