Start with python3, these steps show how to create and use virtual environment for python. This is useful for isolating projects from each other since there are specific version of packages needed in a specific project.
note: This documentation is based on Windows OS env
- install python 3+ (make sure the executable is set in system path to make it easier to use, this document assumes install python is linked in system path by name py)
- create virtualEnvironment using built-in venv
- use
envas the name of folder venv
py -m venv envA folder named env will be created. This can be named based on the command above.
- using/activating the virtual environment
- from previous step
envis the folder where the activate script in
.\env\Scripts\activateOnce activated the python module being installed will be tide to this project and env.
- deactivate the virtual environment
- from inside an activated environment, this command will be available
deactivateAfter activating virtual environment, if running deactivate doesn't work. Should check if there is something wrong with the environment. Easiest way to check is if running pip3 freeze > requirements.txt and see a lot of unknown or unused python packages. There might be virtual environment corruption
solution 1: delete the virtual environment env and reinstate it py -m venv env
solution 2: check python system path, make sure the OS is running python3. Sometimes the system might have multiple version of python running. pip module gets kind of confused
pip used to manage and install python libraries. Helpful commands. Assumes package list name to be requirements.txt for example commands below
Once venv is activated list out all packages under this project
pip3 freezesave package dependency list into a file: requirements.txt
pip3 freeze > requirements.txtinstall packages in file: requirements.txt
pip3 install -r requirements.txt