4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7にてpython3の仮想環境(venv)を作り、Djangoをインストールする手順

Posted at

前提

ユーザ:dev1
python2系はインストール済みであるが、3系は未インストールの環境

手順

python3系のインストール

[dev1@localhost ~]$ python3 -V
-bash: python3: コマンドが見つかりません
[dev1@localhost ~]$ python -V
Python 2.7.5
[dev1@localhost ~]$ sudo yum install epel-release -y
読み込んだプラグイン:fastestmirror
・・・
完了しました!
[dev1@localhost ~]$ sudo yum-config-manager --disable epel
sudo: yum-config-manager: コマンドが見つかりません
[dev1@localhost ~]$ sudo yum -y install yum-utils
読み込んだプラグイン:fastestmirror
・・・
完了しました!
[dev1@localhost ~]$ sudo yum-config-manager --disable epel
読み込んだプラグイン:fastestmirror
・・・
username = 
[dev1@localhost ~]$ sudo yum install --enablerepo="epel" python36 -y
読み込んだプラグイン:fastestmirror
・・・
完了しました!

専用のディレクトリ作成&venv適用

[dev1@localhost ~]$ mkdir -pv $HOME/.venv
mkdir: ディレクトリ `/home/dev1/.venv' を作成しました
[dev1@localhost ~]$ python36 -mvenv $HOME/.venv
[dev1@localhost ~]$ 

venvの有効化

[dev1@localhost ~]$ source $HOME/.venv/bin/activate
(.venv) [dev1@localhost ~]$

venvの無効化

(.venv) [dev1@localhost ~]$ deactivate
[dev1@localhost ~]$ 

venvを有効化した状態でpipをアップグレード

(.venv) [dev1@localhost ~]$ pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d7/41/34dd96bd33958e52cb4da2f1bf0818e396514fd4f4725a79199564cd0c20/pip-19.0.2-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 5.9MB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-19.0.2
(.venv) [dev1@localhost ~]$ pip -V
pip 19.0.2 from /home/dev1/.venv/lib64/python3.6/site-packages/pip (python 3.6)
(.venv) [dev1@localhost ~]$

djangoをpipでインストール

(.venv) [dev1@localhost ~]$ pip install django
Collecting django
  Downloading https://files.pythonhosted.org/packages/36/50/078a42b4e9bedb94efd3e0278c0eb71650ed9672cdc91bd5542953bec17f/Django-2.1.5-py3-none-any.whl (7.3MB)
    100% |████████████████████████████████| 7.3MB 1.9MB/s 
Collecting pytz (from django)
  Downloading https://files.pythonhosted.org/packages/61/28/1d3920e4d1d50b19bc5d24398a7cd85cc7b9a75a490570d5a30c57622d34/pytz-2018.9-py2.py3-none-any.whl (510kB)
    100% |████████████████████████████████| 512kB 8.6MB/s 
Installing collected packages: pytz, django
Successfully installed django-2.1.5 pytz-2018.9
(.venv) [dev1@localhost work]$ python -m django --version
2.1.5
4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?