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 virtualenv in Deepin

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use virtualenv in Deepin. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Virtualenv is a tool for creating isolated python virtual environments. It can create its own python environment in a separate directory, use virtualenv to run programs, and will not access the global python environment, nor will it access the python environment that does not belong to its own directory, so it can play the role of isolating the python environment.

Install virtualenv

When developing Python applications, all third-party packages are installed by pip into Python's site-packages directory. And only one version can be installed, so if we want to develop multiple applications at the same time, all of which share a Python, but different applications rely on different versions of third-party packages, it will be more difficult to deal with.

In this case, you can create an "isolated" Python runtime environment for each application through virtualenv. In this way, the third-party packages that each application depends on can not affect each other.

First, we install virtualenv with pip:

Sudo pip3 install virtualenv

Note: be sure to install with administrator privileges, or you will be prompted that virtualenv cannot be found.

Create a virtual environment

After installing virtualenv, you can create a virtual environment from the command line. For example:

Virtualenv-- no-site-packages .venv

With this command, you can create a new directory called .venv under the current directory, which is the newly created virtual Python runtime environment. Plus the parameter-- no-site-packages indicates that there is no need to copy all third-party packages that have been installed into the system's Python environment.

Using a virtual environment

The virtual environment needs to be entered through the source command.

Source .venv / bin/activate

After executing the command, you can see that the command prompt has a prefix (.venv) indicating that a Python virtual environment named .venv is currently being used.

Indoors31@indoors31-PC:~/Documents/Workspace/Hello$ source .venv / bin/activate

(.venv) indoors31@indoors31-PC:~/Documents/Workspace/Hello$

Exit the virtual environment

Deactivate allows you to exit the virtual environment that is currently in use.

(.venv) indoors31@indoors31-PC:~/Documents/Workspace/Hello$ deactivate

Indoors31@indoors31-PC:~/Documents/Workspace/Hello$

Install virtualenvwrapper

To use virtualenv, you need to enter the corresponding path, and there are some differences between linux and windows. You can simplify the operation of the virtual environment by using virtualenvwrapper.

Installation steps:

Sudo pip3 install virtualenvwrappermkdir $HOME/.virtualenvs saves the directory of the virtual environment vim ~ / .bashrc

Add the command as follows:

Export WORKON_HOME=$HOME/.virtualenvsexport VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenvsource / usr/share/virtualenvwrapper/virtualenvwrapper.sh

Save exit and execute source ~ / .bashrc

Use virtualenvwrapper

You can create a virtual environment through the mkvirtualenv command:

Mkvirtualenv .venv

After execution, a virtual environment named .venv is created in the directory just set by WORKON_HOME and automatically entered.

As with virtualenv, use the deactivate command to exit the virtual environment.

After exiting and entering the virtual environment again, you don't need to find a path like virtualenv. You can directly use the workon command to enter the virtual environment:

Workon .venv

Other commands of virtualenvwrapper r

Mvirtualenv ENV deletes the runtime ENV

Mkproject hello creates hello project and runtime environment hello

Mktmpenv creates a temporary running environment

Lsvirtualenv lists available runtime environments

Lssitepackages lists the packages installed in the current environment

On how to use virtualenv in Deepin to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Servers

Wechat

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

12
Report