How to create a Python virtual environment in Ubuntu 14.04

It is relatively easy to install Python in Ubuntu 14.04. The easiest installation method is to install it with apt-get. For specific tutorials, you can click this article: How to install Python3 and switch between py2 and py3 environments in Ubuntu14.04. Today I will share with you how to create a Python virtual environment on Ubuntu 14.04. The specific tutorial is as follows.

1、 Like Windows, creating a virtual environment in Ubuntu also requires virtualenv, so you must install virtualenv before creating a virtual environment. Enter the command "sudo pip install virtualenv" in the command line and wait for the installation to complete, as shown in the figure below.

If the installation of the above method is not successful, you can try to enter the command "sudo apt-get install python-virtualenv" to install, as shown in the figure below.

2、 After entering pip list in the command line, you can view the installed packages, and you can see that virtualenv is already in it.

3、 Then enter the command "virtualenv demo" in the current directory or switch to a folder where you want to create a virtual environment, where demo is the name of the virtual environment, as shown in the following figure, the virtual environment is created successfully.

4、 Enter the virtual environment demo, and then enter the bin directory. The files inside are not consistent with the virtual environment under Windows, and the method of activating the virtual environment is also inconsistent, as shown in the following figure.

5、 Enter the command "source activate" to activate the virtual environment. At this time, the demo has been enclosed in brackets, as shown in the figure below.

Enter Python at this time, you can see that it is the Python3 environment.

6、 If you want to create a virtual environment of Python2, you need to go back to the folder where you want to create the virtual environment and enter the command "virtualenv –p /usr/bin/python2 py2", where py2 is the name of the virtual environment, as shown in the figure below Show.

7、 The same as the virtual environment of Python3, enter py2, then enter the bin directory, enter the command "source activate" to activate the virtual environment, as shown in the figure below, at this time py2 has been enclosed in brackets.

It should be noted that before switching to the py2 virtual environment, you need to enter the command "deactivate" to exit the previous demo virtual environment, as shown in the figure above.

8、 At this time, enter python in the py2 virtual environment, you can see that the system will automatically switch to the Python2 environment, as shown in the figure below.

9、 If you want to exit the virtual environment, you only need to enter the command "deactivate", as shown in the figure below.

Next, friends can freely create Python virtual environments and switch Python environments in Ubuntu.

Recommended Posts

How to create a Python virtual environment in Ubuntu 14.04
How to install python in ubuntu server environment
How to create a CentOS virtual machine in VMware
How to sort a dictionary in python
Python virtual environment: Ubuntu16.04
How to configure TensorFlow use environment in Ubuntu
How to simulate gravity in a Python game
How to write a confession program in python
How to understand a list of numbers in python
How to install Helm in Ubuntu
How to wrap in python code
How to install mysql in Ubuntu 14.04
How to omit parentheses in Python
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python
How to read Excel in Python
Install Python virtual environment on Ubuntu 18.04
How to view errors in python
How to install mysql in Ubuntu 14.04
How to write return in python
How to understand variables in Python
How to use SQLite in Python
How to find the area of a circle in python
How to set up a Masterless Puppet environment on Ubuntu 14.04
How to install memcache and start it in ubuntu environment
Encountered in the process of building a virtual environment in ubuntu
How to compile and install PHP and Nginx in Ubuntu environment
How to create a Sudo user on Ubuntu [Quick Start]
How to add swap partition in Ubuntu
How to easily compile openJDK in Ubuntu
How to make a globe with Python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How to represent null values in python
How to save text files in python
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to install cuda10.1 driver in Ubuntu
How to write try statement in python
How to delete redundant kernels in Ubuntu
How to delete redundant kernels in Ubuntu
How to define private attributes in Python
How to install ROS Noetic in Ubuntu20.04
How to set static IP in ubuntu14.04
How to add custom modules in Python
How to understand global variables in Python
How to modify software source in Ubuntu 7.10
How to view installed modules in python
How to open root account in Ubuntu20.04
How to install Python2 on Ubuntu20.04 ubuntu/focal64
How to open python in different systems
Build a python development environment under Ubuntu
How to add background music in python
How to represent relative path in python
How to hide applications in Ubuntu Dash?
How to compile and install xdebug from source code in Ubuntu environment
How to expand the ubuntu LVM partition of a VirtualBox virtual machine
How to make the ubuntu virtual machine in vmware display in full screen