Centos7.4 configuring virtual environment

environment

Centos7.4
Python3.7

download

pip isntall virtualenv

create environment

virtualenv environment_name    # for example: virtualenv venv1

This step may remind you when creating a virtual environment.

-bash: virtualenv: No command found

This shows that virtualenv is not added to the environment variables. There are two solutions.
·Specify the Python interpreter to use this virtualenv to create a virtual environment.

python -m virtualenv venv1    # Specify the interpreter of Python.

So what version of the interpreter you use, which version of the interpreter you create the virtual environment is, has the advantage that multiple interpreters coexist, which is more flexible, but the disadvantage is that each time you create a virtual environment you add python-m
· Building soft links for virtualenv
If you have successfully downloaded virtualenv, it is installed in the bin directory of your Python interpreter corresponding to your pip, as I downloaded with Python 3.7, and my Python 3.7 installation directory is / usr / loacl/python/python37/
So my soft company is built like this:

ln -s /usr/local/python/python37/bin/virtualenv /usr/bin/virtualenv

In this way, we can create virtual environment directly with virtualenv after building a soft link.

start and stop

start environment

source venv1/bin/activate    # Success shows (venv1) [root@xx]#

stop environment

source venv1/bin/deactivate    # Or deactivate, when the virtual environment is turned on, it can call deactivate directly.

use

After the virtual environment is opened, the Python interpreter and the PIP are the interpreters of the virtual environment, but with all that said, there is only one virtual environment under centos, and when there are more projects, a virtual environment is not enough. How can we use multiple virtual environments?? How should we manage it?

Posted on Categories default

Leave a Reply

Your email address will not be published. Required fields are marked *