Ubuntu install python3 A virtual environment

Installing a virtual environment

  • step :

  • open Linux terminal ( Shortcut key Ctrl+Alt+T), Enter the command :

sudo apt install python-virtualenv
sudo easy_install virtualenvwrapper

explain : The above two commands are executed one by one , After that, the virtual environment is installed .

Or you can use pip install , The premise is that pip, commonly python Bring it with you pip:

sudo pip install virtualenv
sudo pip install virtualenvwrapper
  • explain : The result of installation as like as two peas , Use either one .
  • virtualenv It's a virtual environment ,virtualenvwrapper Yes virtualenv The command is encapsulated , Make it more friendly .

Be careful : The order of installation cannot be reversed ,virtualenvwrapper Must depend on virtualenv.

Creating a virtual environment

  • Enter the following command at the terminal :
mkvirtualenv Virtual environment name 
Such as :
mkvirtualenv mywork // It creates a name mywork Virtual environment for
  • All the virtual environments created are saved in /home/.virtualenvs Under the table of contents , You can go to this directory to see ;
  • After successful creation, it will automatically enter the virtual environment , Command line prompt changes ;

  • Appoint python Version creates a virtual environment

When the above command is executed , The system will create the default python Version development environment , Generally, everyone's computer will be installed at the same time python2 and python3 edition , Sometimes different versions are needed to create virtual environments .

mkvirtualenv -p python route Virtual environment name 
example :
mkvirtualenv -p /usr/bin/python3 mywork
  • -p refer to path Abbreviation
  • Py Installation path , Default installed in /usr/bin/ Under the table of contents ; If you can't find it for a while , Use command :
whereis python3

Search the terminal command line for , There will be the path you want .

details : There's no need to get into /home/.virtualenvs Catalog , You can execute commands in any directory , All virtual environments are created in the same location .

Be careful : Creating a virtual environment requires networking , Otherwise, the creation fails .

Be careful : Use mkvirtualenv Creating a virtual environment , It may prompt that the command cannot be found , Generally, the script file is not added to the system path , The solution is as follows :

  • Method 1 :
# find virtualenvwrapper Script file for 
whereis virtualenvwrapper
# Enter this directory
cd /usr/local/python3/bin
# Execute script file activation virtualenvwrapper
source virtualenvwrapper.sh
# You can use the command normally
  • Method 2 :
# Method 1: it needs to be activated manually after each restart , inconvenient , Add commands to environment variables 
sudo vi ~/.bashrc
# Add a line at the end
source /usr/local/python3/bin/virtualenvwrapper.sh
# Execute... After saving
source ~/.bashrc
# Now you can use the command normally , And every time the host is restarted, the command will be loaded automatically

View and use of virtual environment

  • Delete virtual environment
rmvirtualenv [ Virtual environment name ]
example :
rmvirtualenv mywork

Be careful : If the current location is in a virtual environment , You need to exit the virtual environment first , Then the deletion can be performed

Be careful : You can delete from any directory , If you don't know the name , Sure rmvirtualen + two Tab key , Tips for all virtual environments

  • Exit virtual environment
deactivate
  • Enter the virtual environment
workon [ Virtual environment name ]
example :
workkon mywork

Be careful : Press workon+ two Tab Key will prompt all virtual environments .

  • View the installed python package
pip list
pip freeze

Both commands can be queried , It's just that the form of display is different .

Install... In a virtual environment python package

  • Enter the virtual environment , Input... At the terminal :
pip install The name of the bag 

Be careful : Never use sudo pip ... , Here is the installation in a virtual environment python package , If used sudo jurisdiction ,python Packages will be installed on the host in a non virtual environment , Can't find this package in the virtual environment .

 

majority Linux Bring their own python2.7, and Ubuntu1.6 Bring your own python3.x, The main record of this article virtualenv+vitualenvwrapper Use python3 A virtual environment

The benefits of virtual environment are not much , Avoid version changes , The function of making development independent of each other

One , First installation virtualenv, command

1 sudo apt-get install python-virtualenv The default is python2

Make

2 sudo apt-get install python3-virtualenv

Two ,  install virtualwrapper

virtualwrapper It is a simple and convenient tool to manage virtual environment , Use command

1 sudo pip install virtualenvwrapper
2 sudo pip3 install virtualenvwrapper

3、 ... and ,    To configure virtualwrapper environment variable

1,vim open ./bashrc

1 sudo vim ~/.bashrc

2, shift+g Get to the end of the text , Add the following

3,./bashrc Only after source ~/.bashrc The order doesn't take effect until after

Four , The use of basic commands

1, Creating a virtual environment

mkvirtualenv Environment name ( This environment is created from the system variable environment , namely py2)

establish python3 Environmental Science

mkvirtualenv --python=/usr/bin/pyhton3 name

2, Enter the virtual environment

workon name

3, Exit virtual environment

deactivate

ubantu install python3 More articles on virtual environment

  1. Ubuntu install python3 A virtual environment

    majority Linux Bring their own python2.7, and Ubuntu1.6 Bring your own python3.x, The main record of this article virtualenv+vitualenvwrapper Use python3 A virtual environment The benefits of virtual environment are not much ...

  2. centos install python3 Virtual environment and python3 install

    1. In this paper, the system command is usually preceded by # Number , To distinguish between system commands and other content . When entering a command , No input required # Number . # yum install vim 2. In this paper, the system output information , I will add >> Number . # whi ...

  3. day 56 linux Installation python3 , A virtual environment ,mysql ,redis

    1.1 download python Source package website :https://www.python.org/downloads/release/python-366/ Download address :https://www.python.org/f ...

  4. Mac Installation on Python3 A virtual environment (VirtualEnv) course

    If it's already installed pip3, Then execute the command to install virtualenv Environmental Science pip3 install virtualenv After installation, check whether the version is installed successfully virtualenv --version Create a new directory M ...

  5. centos7 install python A virtual environment

    This paper mainly introduces centos7 Under the system , install python3 A virtual environment . Environmental Science : System centos7, Source code installation python3,/usr/bin/python3 Installed for yourself . Install support package yum install p ...

  6. Centos6.5 install python3.5 A virtual environment virtualenvwrapper

    Centos6.5 install python3.5 A virtual environment virtualenvwrapper 1 . install python3.5 download :https://www.python.org/ https://ww ...

  7. ContOS7 Compilation and installation python3, Configure virtual environment

    Python36 Compilation and installation One , download python Source package website :https://www.python.org/downloads/release/python-367/ # Download the package to /opt Catalog cd ...

  8. ubuntu16.04 install python3.6, And create a virtual environment ( Use python3.6)

    ubuntu16.04 install python3.6, And create a virtual environment ( Use python3.6) ubuntu16.04 By default python2.7 python3 python3.5.2 ( Be careful : ...

  9. Linux(4)- centos7 install python3、Linux Lower installation 、 To configure virtualenv、 Ensure the consistency of the development environment 、 Virtual environment virtualenvwrapper、vim

    One .centos7 install python3 1. download python3 The source package Download address :https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz cd ...

Random recommendation

  1. Linux Next use inode Delete file

    Linux Sometimes some files can't be used rm Delete directly , For example, the file name of the file contains characters that the terminal cannot display correctly .# ls -litotal 0441511 -rw-r--r-- 1 root root 0 Ap ...

  2. oracle How to specify table field auto increment in

    Background introduction : SQL SERVER Can be in int Type, followed by the identity(1,1), The field will start from 1 Start , according to +1 It's a way of growing , Set this field as the primary key , It's good for us to insert data .MySql Can be used in ...

  3. Yii CModel in rules Validation rule

    array( array(‘username’, ‘required’), array(‘username’, ‘length’, ‘min’=>3, ‘max’=>12), array( ...

  4. select Drop down box to select trigger event

    I always thought that ,select Drop down box to select the right option options Use onclick Just register the event , as follows : <select> <option value="0" ...

  5. data structure ( Chairman tree ):HDU 5654 xiaoxin and his watermelon candy

    Problem Description During his six grade summer vacation, xiaoxin got lots of watermelon candies fro ...

  6. C# Chinese character to Pinyin Translate Chinese into Pinyin

    // Create a public class , For converting Chinese characters public class ChnToPh { // Define the Pinyin area encoding array private static int[] getValue = new int[] { -,-, ...

  7. anaconda Next multi version Python Installation instructions

    Online for multiple versions of Python More and more articles about compatible installation , It's all the experience we have summed up in practice . After several repeated experiments, I still think one of them is more convenient . Someone's installation method is : 1. First install a version of python( Generally speaking, Xian An ...

  8. IIS Release user \&#39;IIS APPPOOL\\X\&#39; Login failed

    I have encountered this problem many times , My solution is to modify the database connection string The solution given online is to change the application pool " Process model ": Reference resources :http://jingyan.baidu.com/album/20 ...

  9. Linux Database operation

    One .mysql Basic operation , Connect to database mysql -u root -p -h 127.0.0.1 mysql -u root -p -h 192.168.12.56 , Grant permission to remote connections grant ...

  10. GDI+ or GdiPlus stay VC6 How to use it under

    1. In your app In the class header file, suppose the following code ( Red letter display ) #if !defined(AFX_WALKLTDEMO_H__826A807C_C01D_4FF0_9248_A6BD0369F3A8__INCLU ...