Visual Studio Code(vscode)에서 Python 작업 공간 설정

6983 단어 pythonbeginnersvscode
프로그래머로서 우리는 (어떤 언어로든) 새 프로젝트를 시작할 때마다 프로젝트를 실행할 환경을 설정해야 합니다. 환경에는 편집기, 프로젝트를 지원하는 패키지, 언어별 린터 및 포맷터 등이 포함될 수 있습니다. 안정적인 환경은 구현의 주요 측면에 집중하고 나머지는 설정에 맡기는 데 도움이 됩니다. vscode에서 Python 환경 설정을 시작하겠습니다.

시작하기 전에 저는 vscode로 작업하는 데 익숙하고 다른 선택이 있을 수 있기 때문에 vscode를 선택했다는 점에 유의하십시오. 코딩 경험을 즐기는 데 도움이 되는 한 완전히 괜찮습니다.

모든 언어에 대한 환경 설정은 다음과 같이 규정할 수 있습니다.
  • Installing language-specific compiler/interpreter
  • Installing a package manager
  • Setting up Virtual Environment
  • Setting up the code editor

  • 1. 언어별 컴파일러/인터프리터 설치

    For python, you will have to install a python Operating system specific interpreter to be able to execute your code. Just visit this link 컴퓨터에 적절한 버전의 Python을 설치합니다. 또한 다음 명령을 사용하여 시스템에 올바르게 설치했는지 확인하십시오.

    $ python --version
    Python 3.7.2
    

    2. 패키지 관리자 설치

    pip is a very popular python package installer. It helps you to manage your python packages. You can visit this link 설치 pip . 다시 말하지만 시스템에 이미 설치되어 있는지 확인하십시오.

    $ pip --version
    pip 20.0.2
    

    3. 가상 환경 설정

    Python applications will often use packages and modules that don't come as part of the standard library (i.e. by the above step). Applications will sometimes need a specific version of a library. It means that there might be multiple applications with different versions of python and/or modules required to run the application. Having one global version being used by all application will not suffice the needs.

    The solution for this problem is to create a virtual environment, a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.

    There are many python packages available for you to create virtual environment python such as virtualenv , pyenv 등 이 게시물에서는 virtualenv를 사용하겠습니다.

    # installing virtual environment
    $ pip install virtualenv
    $ virtualenv --version
    virtualenv 20.0.8
    

    지금까지 우리는 전 세계적으로 모든 것을 설치했습니다. 이제부터는 특정 환경(폴더)에 설치를 제한하는 가상 환경을 만들 것입니다.

    # creating a project folder
    $ mkdir python-demo
    # creating a virtual environment for this project
    $ virtualenv python-demo
    # this will create a virtual environment folder <python-demo> in the current folder
    

    가상 환경을 만든 후에는 이 프로젝트 내부에 이 프로젝트에 대한 다른 모든 Python 패키지를 설치해야 합니다. 이는 다음 명령을 사용하여 가상 환경 활성화를 통해 수행됩니다.

    # for ubuntu
    $ source <virtual-env-folder-path>/bin/activate
    $ source python-demo/bin/activate
    
    # for windows
    $ <virtual-env-folder-path>\Scripts\activate
    $ python-demo\Scripts\activate
    
    # After this, your command prompt/terminal will change the path with the virtual environment name
    (python-demo) $
    
    # to deactivate the virtual environment, just type the command deactivate
    (python-demo) $ deactivate
    $
    

    4. 코드 편집기 설정

    Now, let's move to set up a python environment in the vscode code editor. There are possibly 2 tasks a code editor should perform whenever you write code in it - Linting and Formatting the code. Vscode supports multiple linters and formatters to help you out in your workspace.

    Before we create a workspace setting for our python environment, let's install a linter and a formatter for python. I will be using autopep8 and pylint for the same. You can choose any other python package of your choice, just follow this link

    # Make sure you have activated your virtual environment
    (python-demo) $ pip install autopep8 pylint
    

    나는 vscode에서 파이썬 환경을 위한 settings.json를 만들었습니다.




    vscode 편집기를 업데이트하려면 이 gif를 따르십시오settings.json





    가상 환경 경로를 <your-env-path>로 바꾸는 것을 잊지 마십시오.



    마지막으로 this vscode python extension을 설치하여 vscode에서 Python 지원을 활성화합니다.





    보너스 🔥



    link에 따라 vscode 작업 공간에 디버거 구성을 추가할 수도 있습니다.



    <시간/>

    이 정보가 도움이 되었거나 제안할 사항이 있으면 언제든지 의견을 말해주세요. 또한 제 게시물이 마음에 드셨다면 ❤️ 또는 🦄 누르는 것을 잊지 마세요.



    또 봐요! 다음 포스팅까지 😋

    좋은 웹페이지 즐겨찾기