Python (Windows 10) Virtual Environment / Package with VS Code

Once Python works with VS Code

You can install the package and analyze it, but it will be more convenient if you can create a virtual environment. As a merit of creating a virtual environment

--Even if the environment is buggy, you only have to delete the virtual environment ――Easy to share the environment when working with someone in the same environment --Packages that you don't normally use can only be installed in a virtual environment

I wonder if it is big. By the way, when you install a normal package, you can install it by executing pip install package name in the terminal (powershell). Therefore, if you don't need a virtual environment, you can manage packages around pip. (People who create venv described later in a virtual environment will do it with pip)

Building a virtual environment

It's basically good to make venv (short for ** v ** irtual ** env ** ironment?), But using pipenv made it easier, so I'll introduce that. In the case of venv (I wonder if this expression is correct), powershll goes to the project directory (use the cd command) and then, depending on the version, I only know Python3 So

python3 -m venv virtual environment name

Then you can create a virtual environment. All you have to do is manage the package with pip. At first I used to do this all the time, but it's getting more and more troublesome. .. .. So, if you try the method using pipenv as another environment construction method, it's quite easy. Well, I think venv is okay at all, so I think it's okay if you like it. "Venv: Python virtual environment management" explains this method.

After starting VS Code, go to the terminal, start "new terminal",

pip install pipenv

Just execute. Create a new folder and in a new terminal

pipenv --python 3.8

The part of "3.8" that is executed like this is my Python version, so change it according to your own version. When you run it, Explorer on the left? I wonder if I can do something like ".venv". Then create and open a new file " filename.py ". You can choose the Python to use from " Ctrl + Shift + P "or" Select Python ... "in the lower left to select the Python to use, so you can select the one you just made (maybe parentheses) That's the one with the writing.) The path is also written, so select the one with ".venv /" written somewhere. If you write something and execute it (F5 and ʻEnter`), it will be executed.

Package installation

It is attractive that you can also install packages with pipenv. Install in the terminal

pipenv install package name

When uninstalling with, just do "uninstall" above. If you want to try it out, use numpy (called NumPy, which stands for Numerical Python) that anyone can use (package names are all lowercase). NumPy is a Python package that specializes in numerical calculations, but it may be convenient to put it in because it does quite a lot from the basics.

It's easy, isn't it? So, let's talk a little about sharing. Basically, use pip freeze to create requirements.txt and move it to another PC.

pip install –r requirements.txt

However, if you manage the package with pipenv, it will be appreciated that such files will be updated automatically. That information is stored in the Pipfile. In the case of Pipfile, move to another PC and

pipenv install --dev

You can do like this. Also, if you used to manage packages with requirements.txt,

pipenv install -r ./requirements.txt

If so, the environment can be reproduced on a new PC. It's a really convenient time compared to the past.

Recommended Posts

Python (Windows 10) Virtual Environment / Package with VS Code
Python with VS Code (Windows 10)
Steps to create a Python virtual environment with VS Code on Windows
Virtual environment with Python 3.6
Use Python in Anaconda environment with VS Code
Make your Python environment "easy" with VS Code
Build a python execution environment with VS Code
Debug Python with VS Code
Prepare a Python virtual environment for your project with venv with VS Code
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Build python virtual environment with virtualenv
Create a virtual environment with Python!
Building a virtual environment with Python 3
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
Install python with mac vs code
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
The story that Python stopped working with VS Code (Windows 10)
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
python windows environment
[Python] Create a virtual environment with Anaconda
Building a Python 3.6 environment with Windows + PowerShell
Creating a python virtual environment on Windows
Build a python virtual environment with pyenv
Create a Python environment for professionals in VS Code on Windows
Debug settings in virtual environment when using Pipenv with VS Code
Create a simple Python development environment with VS Code and Docker
How to build Python and Jupyter execution environment with VS Code
VS Code + Azure Functions + Python environment construction procedure
python windows environment construction
Build Python development environment with Visual Studio Code
I was addicted to creating a Python venv environment with VS Code
Create a virtual environment with conda in Python
Debug with VS Code using boost python numpy
python virtual environment Pipenv
Python starting with Windows 7
Image Processing with Python Environment Setup for Windows
virtual environment in python
Python environment with docker-compose
Work in a virtual environment with Python virtualenv.
From Python environment construction to virtual environment construction with anaconda
Create a Python virtual development environment on Windows
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]
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Build a python virtual environment with virtualenv and virtualenvwrapper
Allow real-time code checking in Python development with VS Code
Revive symbol search in Python workspace with VS Code
How to make a Python package using VS Code
Build a python virtual environment with virtualenv and virtualenvwrapper
python package dependencies and virtual environment management tool Poetry
Remote debug Django environment created with docker-compose with VS Code
Get country code with python
Run python with PyCharm (Windows)
Install Python environment with Anaconda
Manage python environment with virtualenv
venv environment with windows powershell
Python environment construction (Windows10 + Emacs)
Build python3 environment with ubuntu 16.04
Build Python environment on Windows