Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)

I decided to develop a web application with Python with an acquaintance, so I made a memorandum.

There is a Windows version of the article in a similar article. (Windows version article)

Create in the following environment so that all members can use the PC owned by the member for free because there are multiple environments of Mac and Windows. For the time being, create up to Intellisense debug execution with VSCODE.

Development environment (confirmed)

・ IDE
VSCode version 1.8.1
·language
  Python3
  Django 1.10.4
・ OS
  Mac OS Sierra

Environment creation

I am working with reference to this article (thanks) Introduction to Python Django (1) -Introduction to Python Django (2) Mac Edition

Python Path and Version pythonVSCode some virtualenv issues #148 Troubleshooting Intellisense Autocompletion

Mac version

1. 1. Install XCODE

A. Install Xcode from the App Store

I. Install Command Line Tools

  $ xcode-select --install

Install with the above command.

2. Install Python3

Python 2 series is installed by default, but since it was planned to be developed in 3, install 3

A. HomeBrew installation

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

Install with the above command

I. Install Python3

$ brew update
$ brew info python3
python3: stable 3.6.0 (bottled), HEAD
$ brew install python3

You can check the version with the following command

$ python3 -V 
Python 3.6.0

3. 3. Installation of virtualenv and virtualenvwrapper

Since virtualenv is a tool to create a Python virtual environment for each development environment, install it.

A. Create a directory for the virtual environment

$ cd
$ mkdir Develop
$ cd Develop
$ mkdir Sandbox
$ cd Sandbox
$ mkdir Python

I think that the location of the directory to be created may be personal preference.

I. Install pip, virtualenv and virtualenvwrapper

$ cd
$ sudo easy_install pip
$ sudo pip install virtualenv virtualenvwrapper --ignore-installed six

C. Modify .bashrc file (create new if not available)

.bashrc


export WORKON_HOME=$HOME/Develop/Sandbox/Python
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
source /usr/local/bin/virtualenvwrapper.sh

WORKON_HOME is the default folder where the virtual environment is created. VIRTUALENVWRAPPER_PYTHON is the path to Python with Virtualenvwrapper installed.

D. Added setting to read .bashrc in .bash_profile

.bash_profile


if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

E. Load .bash_profile

$ source .bash_profile

4. Building a virtual environment

$ mkvirtualenv --no-site-package --python /usr/local/bin/python3 env1

--- Select python3 installed with python Set not to use python site-package which is paste with --no-site-package After the above command, the command line will be displayed as (env1) $ because the virtual environment is being used.

5. Install django

(env1) $pip install django==1.10.4
(env1) $pip freeze -l
Django==1.10.4

6. Create a development site

(env1) $ cd
(env1) $ cd Develop
(env1) $ mkdir PythonSites
(env1) $ cd PythonSites
(env1) $ django-admin.py startproject myTestSite

Please choose the development folder to your liking. In the above, you will have (user directory) / Develop / PythonSites / myTestSite.

7. Install Visual Studio Code

A. Download and install the package

Download and install from Visual Studio Code

I. Install extension

Install Python by typing Python from View> Extensions (Don Jayamanne's guy) スクリーンショット 2017-01-09 13.35.37.png

C. Changed to be able to start from the command line

Enter shell in View> Command Palette and set it so that it can be started with code スクリーンショット 2017-01-09 13.40.27.png

8. Start and set Visual Studio Code

A. Launch VsCode

 $ cd
 $ cd Develop/PythonSites/myTestSite
 $ workon env1
(env1) $ code .

Note that if you do not use the above login method, the default virtual environment settings and other settings will be incorrect.

I. Add workspace definition

setting.js


//Insert settings in this file to override the default and user settings
{
    "python.pythonPath": "${env.PYTHONPATH}/env1/bin/python",
    "python.linting.pylintEnabled": false,
    "python.linting.pep8Enabled": true
}

It is mainly set to make intellisense effective. The location of the file is Code> Basic Settings> Workspace Settings. Set only when you open this workspace.

C. Debug function settings

For the time being, in order to create a template file, click the debug icon from the menu on the left and forcibly execute debugging.

lounch.json


        {
            "name": "Django",
            "type": "python",
            "request": "launch",
            "stopOnEntry": true,
            "pythonPath": "/Users/userName/Develop/Sandbox/Python/env1/bin/python3",
            "program": "${workspaceRoot}/manage.py",
            "cwd": "${workspaceRoot}",
            "args": [
                "runserver",
                "--noreload"
            ],
            "debugOptions": [
                "WaitOnAbnormalExit",
                "WaitOnNormalExit",
                "RedirectOutput",
                "DjangoDebugging"
            ]
        },

If you touch only the PythonPath item, it's OK, please go through the path to the virtual environment.

9. End of Mac version

If you do so far, intellisense スクリーンショット 2017-01-09 14.05.09.png Debug execution スクリーンショット 2017-01-09 14.07.00.png Should work (tabun)

Recommended Posts

Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Prepare Python development environment with Atom
Build Python development environment with Visual Studio Code
Python (Windows 10) Virtual Environment / Package with VS Code
Python with VS Code (Windows 10)
Prepare python3 environment with Docker
Prepare Python development environment on Ubuntu
Set up a Python development environment with Visual Studio Code
Prepare your first Python development environment
[Python3] Development environment construction << Windows edition >>
Install Python development environment on Windows 10
Install python with mac vs code
Prepare the development environment with anyenv
[Python Windows] pip install with Python version
Create a simple Python development environment with VS Code and Docker
Build jupyter notebook environment with Visual Studio Code (VS Code) Mac version
[Python] Building an environment with Anaconda [Mac]
[Development environment] Python with Xcode [With screen transition]
Building a Python 3.6 environment with Windows + PowerShell
Build Python environment with Anaconda on Mac
Prepare the development environment for keyhac for Mac
Windows + gVim + Poetry python development environment construction
python windows environment
Prepare a Python virtual environment for your project with venv with VS Code
Prepare Python development environment for each project in Windows environment (VSCode + virtualEnvWrapper + Pylint)
Create a Python development environment on Windows (Visual Studio Code remote WSL).
Steps to create a Python virtual environment with VS Code on Windows
I tried to build a Mac Python development environment with pythonz + direnv
Introduction to Python Let's prepare the development environment
Prepare the execution environment of Python3 with Docker
Manage Python multiple version environment with Pythonz, virtualenv
[Python] Build a Django development environment with Docker
Image Processing with Python Environment Setup for Windows
Build a Python development environment on your Mac
Use Python in Anaconda environment with VS Code
Create a Python virtual development environment on Windows
Make your Python environment "easy" with VS Code
Build a python execution environment with VS Code
Get a quick Python development environment with Poetry
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
Character code for reading and writing csv files with python ~ windows environment ver ~
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
python windows environment construction
Python development environment construction
Python starting with Windows 7
Prepare a development environment that is portable and easy to duplicate without polluting the environment with Python embeddable (Windows)
About Python development environment
Python environment with docker-compose
python2.7 development environment construction
Development environment in Python
Mac environment construction Python
Virtual environment with Python 3.6
Check version with python
Virtualize (isolate) IBM i python development environment with chroot
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Allow real-time code checking in Python development with VS Code
[Mac OS] Use Kivy with PyCharm! [Python application development]