[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS

This is your own procedure memo for building a Python Django environment (& environment for machine learning). It consisted of "pyenv" + "pyenv-virtualenv" + "Anaconda".

1. Install XCode

Terminal


$ xcode-select --install (#Click the install button when the pop-up window launches)

2. Install Homebrew

Terminal


$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

<reference>
$ brew update && brew upgrade (#Homebrew update)

(Ref 1-2) -Comfortable python environment with MacOS, Homebrew and pyenv.

3. Install pyenv and pyenv-virtualenv

Terminal


$ brew install pyenv
$ brew install pyenv-virtualenv

4. Setting up the .bash_profile file

Terminal


$ vim ~/.bash_profile (# .bash_Describe the following contents in the profile file)

  ## Set path for pyenv
  export PYENV_ROOT="$HOME/.pyenv"
  export PATH="$PATH:$PYENV_ROOT/bin:$PYENV_ROOT/shims"
  # eval "$(pyenv init -)" (#Set as needed)
  # eval "$(pyenv virtualenv-init -)" (#Set as needed)

Terminal


$ source ~/.bash_profile (#Reflect the settings)

5. Install Anaconda (Python 3 and 2) via pyenv

Terminal


$ pyenv install -l | grep anaconda3 (#The latest Anaconda(Python3 series)Check the version of)
$ pyenv install anaconda3-4.3.1 (#Install the latest version)
$ pyenv install anaconda2-4.3.1 (#Install Python2 system as well)
$ python --version
   Python 3.6.1 :: Anaconda 4.3.1 (x86_64)  

$ pyenv global anaconda3-4.3.1 (#The specified version of the virtual environment is set for all directories)
$ pyenv versions
  system
    anaconda2-4.3.1
 * anaconda3-4.3.1

6. Create a Python virtual environment for your Django project

Terminal


$ pyenv virtualenv anaconda3-4.3.1 django001
 (# "django001"With the name, version"anaconda3-4.3.1"Create a new virtual environment for)
$ pyenv versions
  system
    anaconda2-4.3.1
 * anaconda3-4.3.1
  django001
 (#Created earlier in a virtual environment that can be specified with pyenv"django001"Is added)

7. Set up a Python virtual environment in the directory where you want to install Django

Terminal


$ mkdir mydjango (#Directory to install Django"mydjango"Create)
$ cd mydjango (# "mydjango"Move to directory)
$ pyenv local django001 (# "mydjango"Virtual environment in the directory"django001"The set)
$ pyenv versions
  system
    anaconda2-4.3.1
  anaconda3-4.3.1
 * django001
 (#You can automatically enter the virtual environment created by virtualenv just by moving to the specified directory.)

<reference>
$ pyenv local --unset (#Cancel local setting)
$ pyenv uninstall django001 (#Delete the virtual environment created by virtualenv)

(Ref 3-7) -[Note from installing Homebrew to building an Anaconda environment for Python with pyenv] (http://qiita.com/oct_itmt/items/2d066801a7464a676994)

--[Understanding environment variable settings for PATH (Mac OS X)] (http://qiita.com/soarflat/items/d5015bec37f8a8254380)

-[Build a python environment for each directory with pyenv-virtualenv] (http://qiita.com/niwak2/items/5490607be32202ce1314)

-[3 types of workarounds for activate collision problem when pyenv and anaconda coexist] (http://qiita.com/y__sama/items/f732bb7bec2bff355b69)

-[A story about using pyenv, which I hated without eating, was too convenient to sit down] (http://qiita.com/who_you_me/items/09f572c842b1c3fea015)

-[Flow of inserting anyenv, pyenv, pyenv-virtualenv, anaconda for switching python development environment] (http://takemikami.com/2016/10/20/python-anyenv-pyenv-pyenvvirtualenv-anaconda.html)

-[I want to create a nice Python development environment for my new Mac] (http://qiita.com/nakazonor/items/258496fc442f7937c478#_reference-40a15e06a5e731d455ef)

8. Conda and pip updates

Terminal


$ pip install --upgrade pip
$ conda update -y conda (#It is not used here, but it is used when installing the machine learning library. See the article below for details)

(reference) -[[Updated from time to time] pyenv + Anaconda (Ubuntu 16.04 LTS) prepares Python development environment for machine learning all-in-one] (http://blog.algolab.jp/post/2016/08/21/pyenv-anaconda-ubuntu/)

9. Install Django

Terminal


$ cd mydjango
$ pip install django (# "mydjango"Install the latest version of Django in your directory)
 <reference>
 (# "pip install django==1.10"You can specify the version to install with)

$ pip list (#Check if Django is listed in the library list)
  Django (1.11)
  pip (9.0.1)
  setuptools (27.2.0)
  wheel (0.29.0)

(reference) -[From 0 to Django development environment construction to basic operation] (http://qiita.com/tonkatu05/items/d0422a2050d669c72f54)

that's all.

Recommended Posts

[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Python environment construction (pyenv, anaconda, tensorflow)
Building an Anaconda environment for Python with pyenv
Python + Anaconda + Pycharm environment construction
Python environment construction For Mac
Anaconda3 python environment construction procedure
Python3 environment construction (for beginners)
[For beginners] Django -Development environment construction-
Python development environment construction on macOS
Python environment construction (pyenv + poetry + pipx)
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Python3 TensorFlow for Mac environment construction
Python3.6 environment construction (using Win environment Anaconda)
Environment construction with pyenv and pyenv-virtualenv
Django environment construction
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
Python environment construction
Construction of Python local development environment Part 1 (pyenv, pyenv-virtualenv, pip installation)
django environment construction
Python3 + venv + VSCode + macOS development environment construction
python environment construction
Python --Environment construction
pyenv + anaconda + python3
Python and machine learning environment construction (macOS)
Python environment construction
python environment construction
Easy-to-understand explanation of Python Web application (Django) even for beginners (1) [Environment construction]
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
MacOS 10.11 environment construction: Powerline with Anaconda and Dein.vim
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
[Django3] Environment construction and various settings summary [Python3]
Python 3.x environment construction by Pyenv (CentOS, Ubuntu)
From Python environment construction to virtual environment construction with anaconda
Django project environment construction
python windows environment construction
homebrew python environment construction
Python development environment construction
Install python (pyenv, pyenv-virtualenv)
pyenv + fish environment construction
python2.7 development environment construction
Anaconda environment construction memo
Mac environment construction Python
Python environment construction @ Win7
Python environment for projects
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
Build a python environment for each directory with pyenv-virtualenv
Use Python installed with pyenv for PL / Python execution environment
Web application made with Python3.4 + Django (Part.1 Environment construction)
QGIS3 Python plugin development environment construction with VSCode (macOS)
Build a Python development environment using pyenv on MacOS
python (pyenv + pyenv-virtualenv) + CentOS7 installation
Use Anaconda in pyenv environment
Anaconda environment construction on CentOS7
Python environment construction (Windows10 + Emacs)
CI environment construction ~ Python edition ~
OpenCV3 installation for Python3 @macOS
Docker + Django + React environment construction
Anaconda3 × Pycharm environment construction memo
Python environment construction and TensorFlow