In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about how to use virtualenv in python. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
1. What is virtualenv?
Virtualenv is to use different python environments in different projects, and the third-party modules that may be referenced by different projects are different versions. At this time, the modules of each project are separated from each other and do not affect each other by using virtualenv.
two。 How do I install virtualenv?
Windows is installed using pip install virtualenv on the command line.
3. Use virtualenv?
(1) first create a folder named my_project on the desktop, open cmd in my_project, and execute
C:\ Users\ Administrator\ Desktop\ my_project > virtualenv project_envUsing base prefix'c:\\ users\\ Administrator\\ appdata\\ local\\ programs\\ python\\ python37'New python executable in C:\ Users\ Administrator\ Desktop\ my_project\ Scripts\ python.exeInstalling setuptools, pip, wheel...done
(2) enable the new python environment
Running project_name/Scripts/activate.bat linux/Mac in windows runs source project_name/bin/activateC:\ Users\ A\ Desktop\ my_project > project_env\ Scripts\ activate.bat (project_env) C:\ Users\ Administrator\ Desktop\ my_project >
(3) after entering the project environment, the project name appears at the beginning and is enclosed in parentheses
(4) execute pip list
(project_env) C:\ Users\ Administrator\ Desktop\ my_project > pip listPackage Version--pip 19.1.1setuptools 41.0.1wheel 0.33.4
It is found that there are only a few modules necessary to create a virtual environment in the new project environment, which do not affect each other with the python environment in our system, so that each project has its own environment for easy management.
(5) install modules in virtual environment
(project_env) C:\ Users\ Administrator\ Desktop\ my_project > pip install numpyCollecting numpy Downloading https://files.pythonhosted.org/packages/ce/61/be72eee50f042db3acf0b1fb86650ad36d6c0d9be9fc29f8505d3b9d6baa/numpy-1.16.4-cp37-cp37m-win_amd64.whl (11.9MB) | ██ | 11.9MB 345kB/sInstalling collected packages: numpySuccessfully installed numpy-1.16.4
(6) View the installed modules
(project_env) C:\ Users\ Administrator\ Desktop\ my_project > pip listPackage Version--numpy 1.16.4pip 19.1.1setuptools 41.0.1wheel 0.33.4
(7) generate format files for installed modules
(project_env) C:\ Users\ Administrator\ Desktop\ my_project > pip freeze-- local > requirements.txt
As shown in the figure:
(8) exit the virtual environment
(project_env) C:\ Users\ Administrator\ Desktop\ my_project > project_env\ Scripts\ deactivate.batC:\ Users\ Administrator\ Desktop\ my_project > the above is how to use virtualenv in python. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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: 252
*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.