Create a virtual environment on the server centos7 of Django's personal blog website, djangocentos7
1. Install virtualenv
Installation Method
Pip install virtualenv # install pip3 install virtualenv # install it in python2
2. Install virtualenvwrapper
Installation Method
Pip install virtualenvwrapper # install it in python2 pip3 install virtualenvwrapper # install it in python3
Note that both of them must be installed. If only python3 is installed, the workon command cannot be used.
Set
Locate
find / -name virtualenvwrapper.sh
We will find two locations.
/Usr/local/python3/bin/virtualenvwrapper. sh #/usr/bin/virtualenvwrapper. sh # In python3
Later we will use the location in python3.
Edit configuration file
cdvim ~/.bashrc
Add the following two commands to the end and specify the location of the virtual environment.
export WORKON_HOME=~/.virtualenvssource /usr/local/python3/bin/virtualenvwrapper.sh
Execute. bashrc to make the file take effect
source ~/.bashrc
Create a virtual environment
mkvirtualenv -p /usr/bin/python3 blog_env_py3
In this way, the virtual environment blog_env_py3 is created.
You can run the workon command to view the directories of all virtual environments and enter the virtual environment.
workon blog_env_py3
3. Install the dependency package in the virtual environment
Go to blog_test in windows and run the following command to export all packages to be installed:
pip freeze > requirements.txt
Use winscpsoftware to import the generated requirements.txt to linux.
Go to the virtual environment blog_env_py3 in linux and run the following command to install all the packages.
pip install -r requirements.txt
When mysqlclient = 1.3.12 is installed, an error is reported. You need to install another dependency package.
yum install mysql-devel
Check the installed package through pip list.