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 centos7 deploys python3 virtual environment

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

Share

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

Today, I would like to share with you the relevant knowledge points about how centos7 deploys the python3 virtual environment. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

First, deploy Python3 on CentOS

1. Install the dependency package

2. Download the original python code package on the official website

3. Decompress and install

4. Modify the configuration file

First, enter the directory unzipped in the previous step

5. Start compilation and installation

6. Configure shared library files

1) set the shared library directory for all users

# cd / usr/local/src/Python-3.6.5/

# cp libpython3.6m.so.1.0 / usr/local/lib64/

# cp libpython3.6m.so.1.0 / usr/lib/

# cp libpython3.6m.so.1.0 / usr/lib64/

2) refresh environment variables

# source / etc/profile

7. Test python

Python 3.6.5 (default, Mar 29 2019, 17:13:23)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux

Type "help", "copyright", "credits" or "license" for more information.

> > exit ()

8. Test pip3

Pip 9.0.3 from / usr/local/lib/python3.6/site-packages (python3.6)

Second, use the third-party virtual tool Virtualenvwrapper

2. Installing virtualenvwrapper provides a series of commands to make working with virtual environments much more enjoyable. It puts all your virtual environments in one place. More importantly, you only need to run a command to enter your virtual environment, so you don't have to install it in a directory that needs to be as advanced as virtual environment (make sure virtualenv has been installed)

2.2 modify the default environment directory:

Alias rm='rm-i'

Alias cp='cp-i'

Alias mv='mv-i'

If [- f / etc/bashrc]; then

. / etc/bashrc

Fi

# specify interpreter

Export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.6

# this can customize the storage directory of the virtual environment

Export WORKON_HOME=~/.virtualenv

# Project storage directory, which needs to be created by yourself

Export PROJECT_HOME=~/.virtualenv/project_data

# automatically load virtualenvmrapper

Source / usr/local/bin/virtualenvwrapper.sh

2.3 create a directory to store the virtual environment

Mkdir / .virtualenv

2.4 initialize

2.5 basic use: create a virtual environment:

2.6 exit the virtual environment:

Deactivate

[root@redis ld.so.conf.d] # workon test

(test) [root@redis test] # deactivate

2.7 enter the virtual environment:

[root@redis ld.so.conf.d] # workon

Python3

Test

[root@redis ld.so.conf.d] # workon test

(test) [root@redis test] #

2.8 create a project:

(test) [root@redis test] # mkproject test1

Using base prefix'/ usr/local'

New python executable in/ root/.virtualenv/test1/bin/python3.6

Also creating executable in/ root/.virtualenv/test1/bin/python

Installing setuptools, pip, wheel...

Done.

Virtualenvwrapper.user_scripts creating / root/.virtualenv/test1/bin/predeactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/test1/bin/postdeactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/test1/bin/preactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/test1/bin/postactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/test1/bin/get_env_details

Creating / root/.virtualenv/project_data/test1

Setting project for test1 to / root/.virtualenv/project_data/test1

(test1) [root@redis test1] # ls

(test1) [root@redis test1] # ls / root/.virtualenv/project_data/

Test test1

2.10 list the packages installed in the current environment:

Lssitepackages:

(test1) [root@redis test1] # lssitepackages

Easy_install.py pip-19.0.3.dist-info pycache setuptools-40.8.0.dist-info wheel-0.33.1.dist-info

Pip pkg_resources setuptools wheel

2.11 create a temporary operating environment:

Mktmpenv

[root@redis test1] # mktmpenv

Using base prefix'/ usr/local'

New python executable in/ root/.virtualenv/tmp-4aa130f4957b04a/bin/python3.6

Also creating executable in/ root/.virtualenv/tmp-4aa130f4957b04a/bin/python

Installing setuptools, pip, wheel...

Done.

Virtualenvwrapper.user_scripts creating / root/.virtualenv/tmp-4aa130f4957b04a/bin/predeactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/tmp-4aa130f4957b04a/bin/postdeactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/tmp-4aa130f4957b04a/bin/preactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/tmp-4aa130f4957b04a/bin/postactivate

Virtualenvwrapper.user_scripts creating / root/.virtualenv/tmp-4aa130f4957b04a/bin/get_env_details

This is a temporary environment. It will be deleted when you run 'deactivate'.

2.12 upon exit of the temporary environment, delete:

(tmp-4aa130f4957b04a) [root@redis tmp-4aa130f4957b04a] # deactivate

Removing temporary environment: tmp-4aa130f4957b04a

Removing tmp-4aa130f4957b04a...

2.13 Delete the virtual environment:

Rmvirtualenv

[root@redis .virtualenv] # workon

Python3

Test1

Test

[root@redis .virtualenv] # rmvirtualenv python3

Removing python3...

[root@redis .virtualenv] # workon

Test1

Test

2.14 install the package in the virtual environment

All virtual environments are independent under ~ / .virtualenv/project_data and do not affect each other. Install packages in the virtual environment and use pip without root permission

[root@redis .virtualenv] # workon test

(test) [root@redis test] # pip install selenium

Collecting selenium

Downloading https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl (904kB)

100% | ██ | 911kB 15kB/s

Collecting urllib3 (from selenium)

Downloading https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)

100% | ██ | 122kB 11kB/s

Installing collected packages: urllib3, selenium

Successfully installed selenium-3.141.0 urllib3-1.24.1

(test) [root@redis test] # pip list

Package Version

Pip 19.0.3

Selenium 3.141.0

Setuptools 40.8.0

Urllib3 1.24.1

Wheel 0.33.1

(test) [root@redis test] # deactivate

Switch to env_python3.6 to view "No selenium package":

[root@redis test] # workon test1

(test1) [root@redis test1] # pip list

Package Version

Pip 19.0.3

Setuptools 40.8.0

Wheel 0.33.1

These are all the contents of the article "how centos7 deploys python3 Virtual Environment". 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