前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Setup Django environment with Anaconda

Setup Django environment with Anaconda

作者头像
jimmyhzhao
发布2022-04-10 12:00:29
5130
发布2022-04-10 12:00:29
举报
文章被收录于专栏:SkemaloopSkemaloop

It is difficult to manage multiple python environments on a single machine, especially for environments that have different third party libraries to be installed.

As a developer, I am always mess up my development environments, and re installation of whole operating system takes too much time. I am using anaconda to manage my development environment.

Install anaconda

Install anaconda is very straightforward, you can just go ahead to download the installer from the anaconda official portal and run the installer.

Configure proxy for anaconda

Each user can have her own condarc file under the home folder. It is in my folder of /home/hui/.condarc

代码语言:javascript
复制
channels:
  - conda-forge
  - defaults

proxy_servers:
    http: http://127.0.0.1:9090
    https: http://127.0.0.1:9090

ssl_verify: False

Create a dedicated environment for my Django framework

代码语言:javascript
复制
conda create --name webenv3 python=3

My environment webenv3 is based on python 3 version. Of course, you can also create another python 2 version environment for your compatibility testing purpose.

代码语言:javascript
复制
conda create --name webenv2 python=2

Environment switch

You can switch the two separated environments back and forth with conda commands.

代码语言:javascript
复制
(webenv3) hui@hui-TM1701:~$ conda activate webenv2
(webenv2) hui@hui-TM1701:~$ conda activate webenv3
(webenv3) hui@hui-TM1701:~$ conda env list
# conda environments:
#
base                     /home/hui/anaconda3
webenv                   /home/hui/anaconda3/envs/webenv
webenv2                  /home/hui/anaconda3/envs/webenv2
webenv3               *  /home/hui/anaconda3/envs/webenv3

Django framework installation

代码语言:javascript
复制
pip --proxy 127.0.0.1:9090 install djangopython -m django --version
2.2.3mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

Migrate the database changes

代码语言:javascript
复制
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

Start the server

代码语言:javascript
复制
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
July 29, 2019 - 15:15:47
Django version 2.2.3, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Done!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-06-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档