Let's create a virtual environment for Python

Understand why you need a virtual environment and actually create a virtual environment

I want to scrape web information with Python, analyze the information, and go crazy. In doing so, I would like to write about creating a basic environment. I would appreciate it if you could point out any mistakes.

Why you need a virtual environment

Since Python has abundant external libraries, there is a possibility that problems such as the apps that have been running will not work due to one version upgrade.

In particular, you need to be careful when you want to have multiple Python apps coexist on one device. If you are using multiple libraries, the dependency will be broken due to the version difference and it will not work.

To prevent this from happening, if you want to create an app, create a virtual environment and manage the library and version for that app. In short, creating a virtual environment for each application makes it easier to manage later.

How to create a virtual environment

Here, it is performed in the following environment.

Use "venv" to create a virtual environment.

--Open a command prompt. --Change to the directory where you want to work with the cd command. --Execute the virtual environment creation command.
* env02 is a virtual environment name and is arbitrary.


python -m venv env02

--Activate the virtual environment.

c:\venv\env01\Scripts\activate

Try installing jupyter notebook in a virtual environment

Here, I will install jupyter notebook.

--Install jupyter

pip install jupyter

--Install kernel to run jupyter notebook on virtual environment (venv)

pip install ipykernel
ipython kernel install --user --name=env02

--Launch jupyter notebook

(env02) C:\venv\jupyter

--When jupyter notebook starts, create a kernel and change it to the activated virtual environment name. jupyter01.png

--When the kernel changes, let's write the code interactively. jupyter02.png

It seems to be running well. So, if you are thinking of making something with Python, let's master the virtual environment firmly before trouble occurs due to library or version dependence later.

Recommended Posts

Let's create a virtual environment for Python
Create a virtual environment with Python!
Create a Python environment
[Python] Create a virtual environment with Anaconda
[Mac] Building a virtual environment for Python
Create a virtual environment for python on mac [Very easy]
How to create a Python virtual environment (venv)
Create a virtual environment with conda in Python
Building a Python virtual environment
[Venv] Create a python virtual environment on Ubuntu
Building a Python virtual environment
Create a Python virtual development environment on Windows
Create a Python environment on Mac (2017/4)
Building a virtual environment with Python 3
Create a python environment on centos
[Python] Building a virtual python environment for the pyramid tutorial (summary)
Create a python environment on your Mac
Let's create a free group with Python
[Python] Create a Batch environment using AWS-CDK
Creating a python virtual environment on Windows
Create a virtual environment with Python_Mac version
Build a python virtual environment with pyenv
Building a Python development environment for AI development
Add a Python virtual environment to VSCode
Create a Python environment for professionals in VS Code on Windows
Create a Python execution environment for Windows with VScode + Remote WSL
Try using virtualenv, which can build a virtual environment for Python
Create a USB boot Ubuntu with a Python environment for data analysis
Create a Python module
python virtual environment Pipenv
virtual environment in python
Virtual environment with Python 3.6
Python environment for projects
Create a Vim + Python test environment in 1 minute
Ubuntu18.04.05 Creating a python virtual environment in LTS
Create a LINE BOT with Minette for Python
Create a python3 build environment with Sublime Text3
[Python] Web development preparation (building a virtual environment)
Build a simple Python virtual environment without pyenv
Commands for creating a python3 environment with virtualenv
Work in a virtual environment with Python virtualenv.
Procedure for creating a Python quarantine environment (venv environment)
A memo for creating a python environment by a beginner
Let's make a module for Python using SWIG
Create a Python execution environment on IBM i
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Prepare a Python virtual environment for your project with venv with VS Code
Create a Python development environment locally at the fastest speed (for beginners)
Steps to create a Python virtual environment with VS Code on Windows
A memo to create a virtual environment (venv) before Django
Create a Wox plugin (Python)
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Write about building a Python environment for writing Qiita Qiita
Create a function in Python
Python: Creating a virtual environment (venv), starting and stopping
Create a dictionary in Python
Building a Docker working environment for R and Python
Build a python virtual environment with virtualenv and virtualenvwrapper
Python 3.4 Create Windows7-64bit environment (for financial time series analysis)
Create a virtual environment with Anaconda installed via Pyenv
Build a python environment for each directory with pyenv-virtualenv