Build a python execution environment with VS Code

I want to manage the dependency of Python execution environment for each project using VSCode.

To-do list

environment

Install pyenv

Clone pyenv to .pyenv in your home directory. You can use homebrew, but if you want to switch between multiple Python versions, you should clone from github.

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Pass through

Describe the following in .bash_profile and .zshrc.

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

Reboot the shell

source ~/.bash_profile

After rebooting, the pyenv command is available.

List and install Python that can be installed.

Show the installable Python.

pyenv install --list

Install Python by specifying the version. (Install 3.8.0 this time)

pyenv install 3.8.0

Specify the Python to use as follows. (Use pyenv local if you want to specify it locally.)

pyenv global 3.8.0

Make sure that the version reflects 3.8.0.

python --version

Install a virtual environment with venv

Create an independent project for each Python so that it is not affected by other projects. It looks like a feature built under Python 3.x.x.

Create a virtual environment

Create and move the project directory. (It may be directly under your home directory.)

mkdir py_project_1 && cd $_

Do the following in the py_project_1 directory: Create it with the name venv directly under the project directory.

python3 -m venv venv

(It doesn't have to be venv, it can be envdir. In that case, run `` `python3 -m venv envdir```. For the sake of clarity, venv seems to be good.)

Start virtual environment

Run and start source.

source venv/bin/activate

When leaving the virtual environment

deactivate

Manage dependencies for each project.

Create a virtual environment for each python environment project, divide the dependency version, etc., and create an environment that does not affect other projects. (For example, the library installed in project A cannot be used in project B, it is not displayed in pip list, and even if the same library is used, it can be handled even if the version is different.)

Change to the project directory.

cd py_project_1

vscode settings

Add the py_project_1 directory to your vscode workspace.

vscode menu>File>Add folder to workspace

Enter the virtual environment.

source venv/bin/activate

Create settings.json for use with vscode.

mkdir vscode && cd $_
touch settings.json

Check the python path of the virtual environment.

which python

Describe the following in settings.json. Describe the path confirmed by which python in python.pythonPath.

settings.json


{
    "python.pythonPath": "Describe the path confirmed by which python",
    "python.venvFolders": [
        "venv"
    ]
}

Install packages that are only used in virtual environments

Move to the py_project_1 directory, enter the virtual environment, and execute the following command.

pip install pytest

After installing pytest, confirm that it was installed.

pip list

Leave the virtual environment and check the pip installation status (pip list is OK). If pytest is not reflected, you can confirm that you have created an environment that does not affect other projects.

Recommended Posts

Build a python execution environment with VS Code
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Build a python virtual environment with pyenv
Build a modern Python environment with Neovim
Build a Python execution environment using GPU with GCP Compute engine
Create a simple Python development environment with VS Code and Docker
Simply build a Python 3 execution environment on Windows
Build Python development environment with Visual Studio Code
Build a python environment with ansible on centos6
Python (Windows 10) Virtual Environment / Package with VS Code
[Python] Build a Django development environment with Docker
Create a python3 build environment with Sublime Text3
Build a Python environment with OSX El capitan
Quickly build a Python Django environment with IntelliJ
Build a Python machine learning environment with a container
Make your Python environment "easy" with VS Code
Build python3 environment with ubuntu 16.04
Build python environment with direnv
Build a Python environment offline
Prepare a Python virtual environment for your project with venv with VS Code
I was addicted to creating a Python venv environment with VS Code
Steps to create a Python virtual environment with VS Code on Windows
Build a python environment for each directory with pyenv-virtualenv
Build a machine learning application development environment with Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Build python virtual environment with virtualenv
Build Mysql + Python environment with docker
Create a virtual environment with Python!
Building a virtual environment with Python 3
Build PyPy execution environment with Docker
Build a python3 environment on CentOS7
Install python with mac vs code
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Set up a Python development environment with Visual Studio Code
Build a Go development environment with VS Code's Remote Containers
How to build a python2.7 series development environment with Vagrant
Build a python environment with pyenv (OS X El Capitan 10.11.3)
UpNext2 Development Record # 1 Build Python CI environment in VS Code
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Easily build a development environment with Laragon
Build Jupyter Lab (Python) environment with Docker
Build a blockchain with Python ① Create a class
Build a python environment on MacOS (Catallina)
Build a Tensorflow environment with Raspberry Pi [2020]
[Python] Create a virtual environment with Anaconda
Building a Python 3.6 environment with Windows + PowerShell
I want to build a Python environment
Build a Fast API environment with docker-compose
[Linux] Build a jenkins environment with Docker
Build a Python + OpenCV environment on Cloud9
Build AI / machine learning environment with Python
[Linux] Build a Docker environment with Amazon Linux 2
Create a Python environment for professionals in VS Code on Windows
Create a Python execution environment for Windows with VScode + Remote WSL
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a Python environment on your Mac with Anaconda and PyCharm
Try to create a python environment with Visual Studio Code & WSL
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
Build jupyter notebook environment with Visual Studio Code (VS Code) Mac version
Build a C language development environment with a container