Python の仮想環境を作る
仮想環境を作成したいディレクトリへ行き、下記のコマンドを実行します。例として「sample_virtual_environment」という仮想環境を作ります。
python3 -m venv sample_virtual_environment
すると下記の様に Python の実行に必要なファイルやフォルダが一式作成されます。

これで仮想環境の作成は完了です。実際に仮想環境「sample_virtual_environment」を起動するには下記を実行します。
% cd sample_virtual_environment/bin % source activate
下記の様にカッコの中に仮想環境の名前が表示されると思います。
(sample_virtual_environment) %
仮想環境から出たい場合は「deactivate」を実行します。
(sample_virtual_environment) % deactivate %
Django をインストールする
仮想環境で Django をインストールするには、仮想環境を activate した状態で下記を実行します。
(sample_virtual_environment) % pip install django
下記のようなログが表示されて最後の方に「Successfully installed」と出ていれば成功です。
(sample_virtual_environment) % pip install django Collecting django Downloading https://files.pythonhosted.org/packages/b8/6f/9a4415cc4fe9228e26ea53cf2005961799b2abb8da0411e519fdb74754fa/Django-3.1.7-py3-none-any.whl (7.8MB) |████████████████████████████████| 7.8MB 337kB/s Collecting asgiref<4,>=3.2.10 (from django) Downloading https://files.pythonhosted.org/packages/89/49/5531992efc62f9c6d08a7199dc31176c8c60f7b2548c6ef245f96f29d0d9/asgiref-3.3.1-py3-none-any.whl Collecting sqlparse>=0.2.2 (from django) Downloading https://files.pythonhosted.org/packages/14/05/6e8eb62ca685b10e34051a80d7ea94b7137369d8c0be5c3b9d9b6e3f5dae/sqlparse-0.4.1-py3-none-any.whl (42kB) |████████████████████████████████| 51kB 9.6MB/s Collecting pytz (from django) Downloading https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl (510kB) |████████████████████████████████| 512kB 8.1MB/s Installing collected packages: asgiref, sqlparse, pytz, django Successfully installed asgiref-3.3.1 django-3.1.7 pytz-2021.1 sqlparse-0.4.1 WARNING: You are using pip version 19.2.3, however version 21.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. (sample_virtual_environment) %
以上で Django のインストールは完了です。続けて Django プロジェクトそして Django アプリケーションの作成はこちらの記事へ。