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

Centos installs Python virtual environment and how to configure it

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

Share

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

This article to share with you is about Centos installation Python virtual environment and configuration method is how, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after some harvest, not much to say, follow Xiaobian to see it.

virtualenv allows you to create several different virtual environments in your system that do not interfere with each other.

Python 3 virtual environment tool configuration

1. Download Virtual Environment Tools

[root@localhost opt]#pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv

2. Creating virtual environments from the command line

[root@localhost opt]#find /opt/python-3.6.9 -name site-packages All pip3 installed modules will be placed here

[root@localhost opt]#virtualenv --no-site-packages --python=python3 ./ ven1

ps: found prompt no-no-site-packages, then we remove and try again

[root@localhost opt]#virtualenv --python=python3 ./ ven1

We find that we will create a virtual environment of ven1 at the moment, go to the bin directory and find that we have automatically created a compiled installation package for pip3 and python3.

After the creation is complete, you must activate to use this virtual environment. This activation is to modify the path variable.

Use the following command:

3: Activate virtual environment

[root@localhost bin]#source /opt/venv1/bin/activate

effect is as follows

We found that the python3 environment has been switched, and the environment variables have also been added to the path of venv1 we just created, indicating that the virtual environment has been successfully created and effective.

Then we can start to create multiple virtual environments for testing

We create a virtual environment venv1 and install ajango1

We create a virtual environment venv2 and install ajango2

[root@localhost opt]#pip3 install django==1.11.9[root@localhost opt]#which django-admin[root@localhost opt]#django-admin startproject venv1_django119[root@localhost opt]#vim venv1_django119/venv1_django119/settings.py Settings Allow Access [root@localhost opt]#python venv1_django119/manage.py runserver 0.0.0.0:8080

Then open a remote connection window, create a virtual environment, here I use alt+f5 switch test!

[root@localhost opt]#pip3 install django==2.0.1[root@localhost opt]#which django-admin[root@localhost opt]#django-admin startproject venv2_django201[root@localhost opt]#vim venv2_django201/venv2_django201/settings.py Settings Allow Access [root@localhost opt]#python venv2_django201/manage.py runserver 0.0.0.0:8081

The process is much the same, directly on the effect map

final effect

deactivate #Execute this command directly to exit the virtual environment. The system will automatically delete the PATH of venv, which means exiting.

The above is how Centos installs Python virtual environment and configuration methods. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow 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

Development

Wechat

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

12
Report