Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use venv in python3 to create virtual environment under Ubuntu

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you how to use venv in python3 to create a virtual environment under Ubuntu. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

1. The virtual environment follows the project and creates a virtual environment for a single project

(built-in direct use above python3.4, pip install virtualenv)

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

Mkdir pythonprojectcd pythonproject

two。 Create a virtual environment env: python-m venv env

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

4. Install packages, create py files

Pip install xxx

5. Exit the virtual environment: deactivate

2.virtaulenvwrapper

Virtaulenvwrapper is an extension of virtualenv to facilitate the management of virtual environments

Integrate all virtual environments into one directory

1. Installation: pip install virtualenvwrapper

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

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

Export workon_home=~/.virtualenvs

Source / usr/local/bin/virtualenvwrapper.sh

4. Run: source ~ / .bashrc

List virtual environments: workon

Create a new virtual environment: mkvirtualenv

Switch virtual environment: workon [virtual environment name]

Delete virtual environment: rmvirtualenv

Exit the virtual environment: deactivate:

Usage parameter: 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_namemkvirtualenv-p / usr/bin/python f is all the contents of the article "how to create a virtual environment using venv in python3 under Ubuntu". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report