install virtualenv

安装virtualenv

[root@doufupi~]# python -m pip install virtualenv
Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/62/77/6a86ef945ad39aae34aed4cc1ae4a2f941b9870917a974ed7c5b6f137188/virtualenv-16.7.8-py2.py3-none-any.whl (3.4MB)
     |████████████████████████████████| 3.4MB 445kB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-16.7.8
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@doufupi~]# python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB)
     |████████████████████████████████| 1.4MB 638kB/s
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
Successfully installed pip-19.3.1

配置virtualenv:创建独立运行环境

[root@doufupi doufupi]# virtualenv --no-site-packages autotools
Using base prefix '/usr/local'
New python executable in /var/doufupi/autotools/bin/python3.7
Also creating executable in /var/doufupi/autotools/bin/python
Installing setuptools, pip, wheel...
done.
[root@doufupi doufupi]# source ./autotools/bin/
bash: source: ./autotools/bin/: is a directory
[root@doufupi doufupi]# source ./autotools/bin/activate
(autotools) [root@rb3xu8a doufupi]#

安装django

(autotools) [root@doufupi doufupi]# pip install django
Collecting django
  Downloading https://files.pythonhosted.org/packages/43/d6/0aed0b12c66527748ce5a007da4618a65dfbe1f8fca82eccedf57d60295f/Django-3.0-py3-none-any.whl (7.4MB)
     |████████████████████████████████| 7.4MB 900kB/s
Collecting asgiref~=3.2
  Downloading https://files.pythonhosted.org/packages/a5/cb/5a235b605a9753ebcb2730c75e610fb51c8cab3f01230080a8229fa36adb/asgiref-3.2.3-py2.py3-none-any.whl
Collecting pytz
  Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
     |████████████████████████████████| 512kB 753kB/s
Collecting sqlparse>=0.2.2
  Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Installing collected packages: asgiref, pytz, sqlparse, django
Successfully installed asgiref-3.2.3 django-3.0 pytz-2019.3 sqlparse-0.3.0

验证django
autotools) [root@doufupi doufupi]# python
Python 3.7.5 (default, Dec  2 2019, 22:35:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> exit()
autotools) [root@rb3xu8a doufupi]# deactivate

验证django在独立的环境中

root@doufupi doufupi]# python
Python 3.7.5 (default, Dec  2 2019, 22:35:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
>>>
创建项目

(autotools) [root@doufupi autotools]# pwd
/var/doufupi/autotools
[root@doufupi doufupi]# source ./autotools/bin/activate

(autotools) [root@doufupi doufupi]# python
Python 3.7.5 (default, Dec  2 2019, 22:35:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> exit()
(autotools) [root@doufupi doufupi]# django-admin startproject Helloworld

(autotools) [root@doufupi Helloworld]# python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

December 03, 2019 - 15:17:03
Django version 3.0, using settings 'Helloworld.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
^C(autotools) [root@doufupi Helloworld]# python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK
(autotools) [root@doufupi Helloworld]# python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
December 03, 2019 - 15:17:58
Django version 3.0, using settings 'Helloworld.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

posted on 2019-12-03 21:22  InnoLeo  阅读(459)  评论(0编辑  收藏  举报