In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to use the Python virtual environment under the Linux system, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Hello, Hello friends, it is also a day of daily get new skills, today, let's take a look at how to play with the Python virtual environment under Linux, 0 basic introduction, video tutorials have also been sorted out, just in the study partner, can get pull! Get in the car while it's hot!
Have previously written about the creation and basic use of the virtual environment under Windows, interested friends can take a look, hand-in-hand teach you how to configure the Python virtual environment, how to create a designated virtual environment under Windows, talk about the virtual environment management tool virtualenvwrapper, hand-in-hand teach you how to load and use the virtual environment in Pycharm.
/ 2 Why do you need virtual environment /
In fact, the fundamental problem to be solved in virtual environment is the confusion of all kinds of third-party packages.
If you receive three projects at the company,
One is using Django1.5, the old project.
One is to use Django1.8, the most recent project
One is using Django2.0+, 's new project.
You can only install one Django per computer, so what to do, you need a tool to separate the various versions.
This is just a situation, our big Python is most proud of a large number of third-party packages, when a project and another project of a large number of packages and the same package, it is over, no one can maintain this project except you.
Next, we will introduce the most commonly used and standardized third-party package.
Virtualenv
Add a package management tool
Virtualenvwrapper
With these two, the above problems are floating clouds.
/ 3 Overview of Linux environment /
This example is version 18.04 of Linux Ubuntu, as shown in the following figure.
The Python version comes with 3.6.9, as shown in the following figure.
The pip version has been updated to the latest, as shown in the following figure.
Pip update command:
Sudo Python3-m pip install-- upgrade pip
/ 4 installation configuration /
1. Install virtualenv
Pip install virtualenv
two。 Install virtual environment management tools
Pip install virtualenvwrapper
/ 5 procedure /
1. Create a folder to store the virtual environment
Mkdir $HOME/.virtualenvs
Or
Mkdir .virtualenvs
In fact, under the current home directory, ~ means the current home directory, if it has been under ~, you don't need $HOME.
. The beginning is a hidden file, and a command is required
Ls-al
To see it.
two。 Execute a command
Which Python3
Look at the directory where Python is installed, as shown in the following figure.
3. Execute a command
Which virtualenvwrapper.sh
View the directory of virtualenvwrapper.
The red part is actually my home catalog, and it's OK to abbreviate it to ~ /.
4. Modify the. / bashrc file, using the command:
Vim .bashrc
You need to have a basic vim here. If you are not familiar with vim, take a look back.
Add content, as shown below.
Export WORKON_HOME=$HOME/.virtualenvs
Source ~ / .local/bin/virtualenvwrapper.sh # which virtualenvwrapper.sh command to get
VIRTUALENVWRAPPER_PYTHON=/usr/bin/Python3 # which Python3 command to get
5. Refresh the configuration file
Source .bashrc
/ 6 Common commands /
1. Create a new virtual environment
Mkvirtualenv spider
Create a new virtual environment of spider and enter the environment of spider.
(spider) indicates that you have entered the virtual environment of spider and are in use, as shown in the following figure.
two。 Exit the current virtual environment
Deactivate
3. View all virtual environments
Workon or lsvirtualenv
These two commands are generally acceptable.
Two have been created, flask and spider, as shown in the figure above.
4. Delete virtual environment
Rmvirtualenv flask
Flask virtual environment has been deleted
5. Enter a virtual environment
Tips
Even if you do not exit the current virtual environment, workon can switch directly to another virtual environment.
In Linux, commands in virtual environment can be completed automatically by tab key.
7 Command Summary
8 Summary
The main content is to operate the Python virtual environment under the Linux system, and enumerates the common commands and basic usage of the virtual environment.
After reading the above, have you mastered how to use the Python virtual environment under the Linux system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.