- How to start Python Development with Python Environment
- 1. Install
python3-venv
orpython3.x-venv
- 2. To create a virtual environment, decide which directory where you want to place it
- 3. Run
venv
module 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.txt
file - 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-venv
You can create a new directory to start your new python app development.
python3 -m venv tutorial-venv
That 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/activate
After 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-name
or by directly using the pip command:
pip install package-name
by giving the ==
followed by the version number after the package name.
pip install package-name==2.6.9
pip install --upgrade package-name
pip uninstall package-name
pip show package-name
pip list
pip freeze > requirement.txt
This 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.txt
This will run pip install package-name
repeatedly as many the packages listed in requirement.txt
.