[Python/Django] Summary of frequently used commands (2) <Installing packages>

background

Here are some frequently used commands when developing with Python/Django.

I would like to take this opportunity to thank you for solving the problem by borrowing the wisdom of our predecessors, and I am very sorry to say that I will summarize it here as my own memo.

environment

(Production environment)

(Development environment)

1. Install packaged software

Python makes it easy to install a wide variety of packaged software over the Internet using the "pip" command. You can check what kind of package software is available on PyPI (The Pyhon Package Index).

Enter the Python virtual environment and do the following:

Terminal


(venv_<Project name>)$pip install django to install the latest version
(venv_<Project name>)$ pip install django==3.1.3 When installing the specified version

You can check the version of the installed package below.

Terminal


(venv_<Project name>)$ python -m django -- version

3.1.3

Installation of other packages (example)

Terminal


(venv_<Project name>)$ pip install psycopg2-binary
(venv_<Project name>)$ pip install django-allauth
(venv_<Project name>)$ pip install pillow
(venv_<Project name>)$ pip install selenium
(venv_<Project name>)$ pip install boto django-ses
(venv_<Project name>)$ pip install gunicorn
Module name Explanation
psycopg2-binary Driver used when connecting to PostgreSQL from Python * 2020/As of 12, psycopg3 is under development
django-allauth Authentication feature package that supports local and social authentication
pillow Package used when handling static files uploaded through web applications
selenium Package used for test method using Live Server Test Case class * SeparatelyDriver for ChromeIs necessary
django-ses Amazon SES(Simple Email Service)Packages required to use
gunicorn (AbbreviationforGreenUnicorn)Pythonwsgi(WebServerGatewayInterface)HTTP server

Extra: Upgrade pip itself

Occasionally, pip itself has been upgraded, so when you execute the pip command, "Upgrade! Please. In such a case, do the following:

Terminal


$ python -m pip install --upgrade pip

2. Create a list of installed modules

Write the modules installed in the Python development environment to a file. Then, based on the exported file, install the module in the production environment.

2-1. Output the list of installed modules to a file.

Terminal


(venv_<Project name>)$ pip freeze > requirements.txt

requirements.txt(Example)


appdirs==1.4.4
astroid==2.4.2
beautifulsoup4==4.9.3
certifi==2020.11.8
chardet==3.0.4
colorama==0.4.4
distlib==0.3.1
filelock==3.0.12
idna==2.10
isort==5.6.4
lazy-object-proxy==1.4.3
mccabe==0.6.1
numpy==1.19.4
pandas==1.1.4
Pillow==8.0.1
pipenv==2020.11.15
pylint==2.6.0
python-dateutil==2.8.1
pytz==2020.4
requests==2.25.0
selenium==3.141.0
six==1.15.0
soupsieve==2.0.1
toml==0.10.2
urllib3==1.26.2
virtualenv==20.1.0
virtualenv-clone==0.5.4
wrapt==1.12.1

2-2. Transfer the exported requirements.txt to the home directory of the production environment.

2-3. Enter the python virtual environment and execute the following to execute the installation.

Terminal


(venv_<Project name>)$ pip install -r requirements.txt

(Relation)

[Python/Django] Summary of frequently used commands (1) <Creating virtual environment, project, application> [Python/Django] Summary of frequently used commands (3) [Python/Django] Summary of frequently used commands (4) -Part 1- <Production operation: Amazon EC2 (Amazon Linux 2)> [Python/Django] Summary of frequently used commands (4) -Part 2- <Production operation: Amazon EC2 (Amazon Linux 2)>


(Editor's note)

It's surprisingly easy to forget to install django-ses. At the time of testing, one of the reasons is that logs and email contents are output to the console, but when I was just starting to create an application, I often said "django-ses is not enough!" I was angry. When creating a website or web application that uses user authentication or sets up an inquiry form, you should almost always take care of django-ses, so pay attention to the package to be installed. I would like to proceed with development.

Recommended Posts

[Python/Django] Summary of frequently used commands (2) <Installing packages>
[Python/Django] Summary of frequently used commands (3) <Operation of PostgreSQL>
[Anaconda3] Summary of frequently used commands
Summary of frequently used commands of django (beginner)
Summary of frequently used commands in matplotlib
Summary of frequently used commands (with petit commentary)
[Python/Django] Summary of frequently used commands (4) -Part 2- <Production operation: Amazon EC2 (Amazon Linux 2)>
List of frequently used Linux commands
[Linux] Review of frequently used basic commands 2
[Linux] Review of frequently used basic commands
[Machine learning] List of frequently used packages
pyenv Frequently used commands
Frequently used tmux commands
Frequently used Linux commands
Frequently used Linux commands
Frequently used linux commands
Summary of frequently used Python arrays (for myself)
[Linux command] A memorandum of frequently used commands
Selenium webdriver Summary of frequently used operation methods
Frequently used pip commands
A collection of commands frequently used in server management
Display a list of frequently used commands on Zsh
Frequently used subpackages of SciPy
Frequently used commands in virtualenv
8 Frequently Used Commands in Python Django
Linux Frequently Used Commands [Personal Memo]
[Linux] Frequently used Linux commands (file operation)
Frequently used Linux commands (for beginners)
[Linux] Frequently used Linux commands (folder operation)
[Linux] Summary of middleware version confirmation commands
[Linux] List of Linux commands used in practice
Summary of stumbling blocks in installing CaboCha
Summary of petit techniques for Linux commands
List of frequently used built-in functions and methods
Summary of what was used in 100 Pandas knocks (# 1 ~ # 32)
Summary of tools used in Command Line vol.8
Summary of tools used in Command Line vol.5
Summary of evaluation functions used in machine learning
Frequently used methods of Selenium and Beautiful Soup
Summary of error handling methods when installing TensorFlow (2)
A memorandum of commands, packages, terms, etc. used in linux (updated from time to time)
Docker. Set frequently used commands to alias "with explanation"
Summary of Linux (UNIX) commands that appeared in Progate
Python --Explanation and usage summary of the top 24 packages
Summary of Pandas methods used when extracting data [Python]
Comparison table of frequently used processes of Python and Clojure
[For beginners] Django Frequently used commands and reference collection