Search code examples
pythonpython-3.xpycharmpython-venvpython-3.10

How to create venv


I have been using my python v3.9 in my virtual environment, it contains all the packages and scripts i have been using for so long. But, now with the release of python v 3.10 it installed itself globally though I wanted it to be installed in same venv I was using for python v3.9 So, if anyone could help me with how can I install python v3.10 in the same venv of my v3.9 . My IDE is PyCharm


Solution

  • Simply put all the dependencies of your python 3.9 (venv) in requirements.txt file

    pip freeze > requirements.txt
    

    Create a new folder then move that file inside the newly created folder then execute the following code, it will create a new virtual environment with python 3.10

    python -m venv newenv
    

    activate the newly created environment by

    source newenv/bin/activate
    

    then install the required dependencies by

    pip install -r requirements.txt
    

    Note: If your OS do not have 'venv' module then simply install it by using

    pip install venv