Create a virtual environment using venv in python3 in Ubuntu

Create a virtual environment using venv in python3 in Ubuntu

1. Virtual environment follows the project, create a virtual environment for a single project

(Python 3.4 and above come with built-in virtualenv, pip install virtualenv)

1. Create a project directory: (find a directory)

mkdir PythonProject
cd PythonProject

2. Create a virtual environment env: python -m venv env

3. Activate the virtual environment: source env/bin/acticate

4. Install the package and create a py file

pip install xxx

5. Exit the virtual environment: deactivate

2. Virtaulenvwrapper

Virtaulenvwrapper is an extension package of virtualenv, which is used to facilitate the management of virtual environments

Integrate all virtual environments into one directory

1. Installation: pip install virtualenvwrapper

2. Create a virtual environment storage directory: mkdir ~/.virtualenvs

3. Add in ~/.bashrc: sudo vim /home/[username]/.bashrc

export WORKON_HOME=~/.virtualenvs

source /usr/local/bin/virtualenvwrapper.sh

4. Run: source ~/.bashrc

List the virtual environment list: workon

Create a new virtual environment: mkvirtualenv

Switch virtual environment: workon [virtual environment name]

Delete a virtual environment: rmvirtualenv

Exit the virtual environment: deactivate:

Use parameters: mkvirtualenv -no-site-packages env

(All third-party packages that have been installed in the system Python environment will not be copied)

5. Create a virtual environment based on the Python version

Query Python path: which python , whereis python

mkvirtualenv -p /xx/xx/python env_name
mkvirtualenv -p /usr/bin/python f

Summarize

The above is what I introduced to you about using venv in python3 to create a virtual environment in Ubuntu. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed explanation of creating and using Python virtual environment
  • Analysis of Python virtual environment creation and package download process
  • Diagram of the process of creating a Python virtual environment based on virtualenv
  • Steps to create a virtual environment in Python 3 in Win10
  • How to install Python3 and create a virtual environment under CentOS
  • Solve the problem that the python virtual environment cannot load the deleted package
  • Python virtualenv virtual environment configuration and usage tutorial detailed explanation
  • Python venv virtual environment configuration process analysis
  • Detailed tutorial on installing Python 3 virtual environment in Ubuntu 20.04
  • Quickly create a Python virtual environment

<<:  Detailed explanation of MySQL index principles and optimization

>>:  Detailed explanation of the principle and example of the new operator in JavaScript

Recommend

HTML solves the problem of invalid table width setting

If you set the table-layer:fixed style for a tabl...

Ubuntu 20.04 sets a static IP address (including different versions)

Because Ubuntu 20.04 manages the network through ...

JavaScript mobile H5 image generation solution explanation

Now there are many WeChat public account operatio...

A brief discussion on several specifications of JS front-end modularization

Table of contents Preface The value of front-end ...

Write a React-like framework from scratch

Recently I saw the article Build your own React o...

Implementation of deploying war package project using Docker

To deploy war with Docker, you must use a contain...

JavaScript canvas implements graphics and text with shadows

Use canvas to create graphics and text with shado...

How to set up ssh password-free login to Linux server

Every time you log in to the test server, you alw...

How to use vite to build vue3 application

1. Installation Tip: There is currently no offici...

MySQL 5.7.17 installation and configuration graphic tutorial

The blogger said : I have been writing a series o...

Docker advanced method of rapid expansion

1. Command method Run the nginx service in the cr...

MAC+PyCharm+Flask+Vue.js build system

Table of contents Configure node.js+nvm+npm npm s...

Summary of the Differences between SQL and NoSQL

Main differences: 1. Type SQL databases are prima...

Detailed explanation of tcpdump command examples in Linux

Preface To put it simply, tcpdump is a packet ana...