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

Life cycle and hook functions in Vue

Table of contents 1. What is the life cycle 2. Th...

Introduction to user management under Linux system

Table of contents 1. The significance of users an...

New ways to play with CSS fonts: implementation of colored fonts

What if you designers want to use the font below ...

Detailed tutorial on building a local idea activation server

Preface The blogger uses the idea IDE. Because th...

express project file directory description and detailed function description

app.js: startup file, or entry file package.json:...

How to view server hardware information in Linux

Hi, everyone; today is Double 12, have you done a...

Centos8 bridge static IP configuration method in VMware virtual machine

1. Make sure the network connection method is bri...

Nginx service 500: Internal Server Error one of the reasons

500 (Internal Server Error) The server encountere...

W3C Tutorial (13): W3C WSDL Activities

Web Services are concerned with application-to-ap...

The unreasonable MaxIdleConns of MySQL will cause short connections

1 Background Recently, some performance issues ha...

How to start the spring-boot project using the built-in linux system in win10

1. Install the built-in Linux subsystem of win10 ...

Detailed explanation of Vue life cycle functions

Table of contents Lifecycle Functions Common life...

React hooks pros and cons

Table of contents Preface advantage: shortcoming:...