Make a note as a memorandum.
I referred to the following article.
Qiita: Python environment construction on Mac
With the goal of installing the following and debugging on VS Code, The procedure is described below.
pyenv-virtualenv is a tool that manages the version of the operating environment, like rbenv in ruby and nvm in node.js. Not only is it easy to switch versions for each application, but it is also possible to create virtual environments within the same version.
Install from brew
$ brew install pyenv-virtualenv
Add the following to bash_profile
vi ~/.bash_profile
export PYENV_ROOT=/usr/local/var/pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
Reflect the settings and check if it works properly
$ source ~/.bash_profile
$pyenv
Get a list of installable Python versions
$ pyenv install --list
Install the latest version as of the time of writing the article
$ pyenv install 3.5.2
Update the global environment after the installation is complete
$ pyenv global 3.5.2
Just in case, make sure that the python version is set to global
$ python --version
Create a virtual environment with pyenv-virtual and apply it to the created working folder.
based on current environment
$ pyenv virtualenv 3.5.2 env_352`$ mkdir dev
$ cd dev
$ pyenv local env_352`flake8 is Python's Linter.
pip install flake8
yapf
yapf is a Python code formatting tool.
pip install yapf
mypy
mypy is a code analysis tool. It does type checking statically like Typescript.
I personally feel relieved to have it, so I will introduce it.
pip install mypy
Ctrl + Shift P
and enter ʻExtensions: Install Extensions`Python
and install the top hitsCode → Preferences → Workspace Settings
at the top left of the screen and add the following itemspython
{
"python.linting.flake8Enabled": true,
"python.formatting.provider": "yapf",
"python.linting.mypyEnabled": true
}
Open the debug screen with Cmd + Shift + D
, click the gear mark on the upper left, and click
To add an item to test the currently open file, add the following description.
python
{
"name": "Test This",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config.python.pythonPath}",
"program": "${file}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
F5
to confirm that it is displayed normally in the Debug Console.print('Hello, World')
Recommended Posts