- How to start Python Development with Python Environment
- 1. Install
python3-venvorpython3.x-venv - 2. To create a virtual environment, decide which directory where you want to place it
- 3. Run
venvmodule as a script in your chosen directory path - 4. Activate your virtual environment
- 5. You can start installing your packages
- 1. Installing a package:
- 2. Installing a package using specific version
- 3. Upgrading a package
- 4. Uninstalling a package
- 5. Showing the details of a package
- 6. Listing all packages installed in your environment
- 7. Exporting installed packages to
requirement.txtfile - 8. Installing packages from exported
requirement.txt
- 1. Install
This is used to use a virtual environment to install packages instead of modifying the system-wide environment. You should create a virtual environment in every python app development to make your system clean and bug-free from bugged pip packages.
The virtual environment is also used to separate your packages in python app development. Normally, you will have different packages in one python app to another.
You can start by following this documentation to learn how to make it by clicking this link: https://docs.python.org/3/tutorial/venv.html
Or you can follow my simple instruction to create a virtual account until you can activate it. But I'm strongly recommend you to read that documentation.
If your system doesn't have venv library, install it using apt.
sudo apt install python3-venvYou can create a new directory to start your new python app development.
python3 -m venv tutorial-venvThat command will create a new tutorial-venv directory in your directory. The new directory contains a copy of Python interpreter and various supporting files.
Based on the documentation, you should create virtual environment directory called .venv. Read more about it in the documentation.
on Windows, run:
tutorial-env\Scripts\activate.bat
on Unix or MacOS, run:
source tutorial-env/bin/activateAfter you run one of those command, the terminal or command prompt you used will show what virtual environment you are using.
These commands is used to manage pip packages.
through python command:
python -m pip install package-nameor by directly using the pip command:
pip install package-nameby giving the == followed by the version number after the package name.
pip install package-name==2.6.9pip install --upgrade package-namepip uninstall package-namepip show package-namepip listpip freeze > requirement.txtThis will create a file called requirement.txt. That file contains a list of the packages you installed in your virtual environment (venv).
pip install -r requirement.txtThis will run pip install package-name repeatedly as many the packages listed in requirement.txt.
