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 > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to use Virtualenv in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
$pip install virtualenv// or use sudo to temporarily promote permissions due to permission problems $sudo pip install virtualenv
2. Basic use of virtualenv
Now start using virtualenv to manage the python environment
➜Test git: (master) ✗ virtualenv ENV # creates a directory called ENV and installs ENV/bin/python, creates a lib,include,bin directory, and installs pipNew python executable in Installing setuptools Pip...done. ➜Test git: (master) ✗ cd ENV➜ ENV git: (master) ✗ lldrwxr-xr-x 14 andrew_liu staff 476 12 8 08:49 bindrwxr-xr-x 3 andrew_liu staff 102 12 8 08:49 includedrwxr-xr-x 3 andrew_liu staff 102 12 8 08:49 lib
Lib, all installed python libraries will be placed under lib/pythonx.x/site-packages/ in this directory
Bin,bin/python is the python interpreter used in the current environment
If you run virtualenv-- system-site-packages ENV on the command line, all libraries under / usr/lib/python2.7/site-packages will be inherited, and the latest version of virtualenv has access to global site-packages as the default behavior
Default behavior.
2.1. Activate the virtualenv#ENV directory using the following command ➜ENV git: (master) ✗ source. / bin/activate # activate the current virtualenv (ENV)➜ ENV git: (master) ✗ # Note the terminal has changed # use pip to view the current library (ENV) ➜ENV git: (master) ✗ pip listpip (1.5.6) setuptools (3.6) wsgiref (0.1.2) # found that there are only three pip freeze # Show all dependencies on pip freeze > requirement.txt # to generate requirement.txt files pip install-r requirement.txt # generate the same environment 2.2 according to requirement.txt. Close virtualenv
Use the following command
$deactivate2.3. Specify python version
You can use the-p PYTHON_EXE option to specify the python version when creating a virtual environment
# create python2.7 virtual environment ➜Test git: (master) ✗ virtualenv-p / usr/bin/python2.7 ENV2.7Running virtualenv with interpreter / usr/bin/python2.7New python executable in ENV2.7/bin/pythonInstalling setuptools Pip...done.# creates python3.4 virtual environment ➜Test git: (master) ✗ virtualenv-p / usr/local/bin/python3.4 ENV3.4Running virtualenv with interpreter / usr/local/bin/python3.4Using base prefix'/ Library/Frameworks/Python.framework/Versions/3.4'New python executable in ENV3.4/bin/python3.4Also creating executable in ENV3.4/bin/pythonInstalling setuptools, pip...done.
At this point, the problems of python version conflicts and different versions of python libraries can be solved.
3. The other 3.1. Generate a packable environment
Under some special requirements, there may be no network. We expect to package an ENV directly, which can be decompressed and used directly. In this case, you can use the virtualenv-relocatable instruction to modify the ENV to an ENV that can be relocated.
# change the currently created virtual environment to transferable ➜ENV3.4 git: (master) ✗ virtualenv-- relocatable. / Making script. / bin/easy_install relativeMaking script. / bin/easy_install-3.4 relativeMaking script. / bin/pip relativeMaking script. / bin/pip3 relativeMaking script. / bin/pip3.4 relative3.2. Get help $virtualenv-h
The current ENV has been modified to a relative path, so you can package the current directory and upload it to another location for use.
This does not enable virtual environments to be used across platforms.
This is how the Virtualenv in the Python shared by the editor is used. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to 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: 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.