


Windows installs Virtualenv to create an independent Python environment
Sometimes we need to call different versions of Python packages and modules in our programs, so the virtual environment of Virtualenv can help us isolate them. Next, let’s take a look at installing and using Virtualenv in Windows to create an independent Python environment. Method
0. When will virtualenv be used?
Assume that there are two applications in the system. Among them, application A requires version 1 of the library LibFoo, while application B requires version 2 of the same library LibFoo. The requirements of the two applications for the same library are as follows: There is a conflict, and the libraries in the system are installed to /usr/lib/python2.7/site-packages by default. So how can we use these two applications at the same time?
Your user rights are insufficient to install packages into the site-packages directory
You need to use an application and be independent from other applications in the system.
If you encounter the above problems, then virtualenv will help you. Virtualenv can create an environment with its own installation directory without interfering with the system's shared libraries or other virtualenv environments.
1. Install virtualenv
Before installing virtualenv, we need to install at least one version of Python; because virtualenv is a third-party module of python, it must be installed based on the python environment. ;
If your python environment has pip, then use the command directly:
pip install virtualenv
to install; otherwise you need to download the source code, and then use the command: python install setup.py to install
After installation, you need to create a new independent environment for virtualenv. For details, you can view its help command:
virtualenv -h
Commonly used parameters are:
-p: Specify a version of the python environment; usually used when multiple python versions are installed in your system; by default virtualenv will give priority to its host python environment, That is, which version of Python it is installed under will be selected as the default Python isolation environment by default.
--no-site-packages: Do not use the python installation package of the system environment, that is, the installation package of the real python environment cannot be used in the isolation package; this option is the default in the current version.
--system-site-packages: Contrary to the above, it enables the isolated environment to access the python installation package of the system environment
--distribute: Copy a branch of the python environment. By default, setup, pip, wheel and other basics will be installed. Module
2. Activation
After the installation is complete, you can create an isolation environment. Use the command:
virtualenv envname ##创建一个新的隔离环境 cd envname Scripts\activate ##激活并切换到virtualenv环境
3. After using
to create and activate the virtualenv environment, we can use and install the python installation package and modules in the normal way. You can also directly switch to the directory of the python file that needs to be executed and use python xxx.py to ensure that the python file is executed in an isolated environment.
That is: before we need to use the virtualenv environment, we only need to activate it first and then use the same method to perform python operations and run python files
cd my_project_folder virtual ENV source bin/activate deactivate
The above is the basic usage process of virtualenv. First, virtual ENV will create a virtual environment named ENV in the current directory. At this time, three directories will be automatically generated in the current directory: bin, include and lib. The virtual environment created by default will depend on the site-packages in the system, that is, the libraries already installed in the system can still be used in the virtual environment. If you want to remove the dependency, you can:
virtualenv --no-site-packages ENV
. The virtual environment in the current directory can be started through source bin/activate. After startup, the shell prompt will change, indicating that it has entered the virtual environment. Use deactivate to leave the virtual environment.
4. Integrate into the development environment
Currently, PyCharm supports virtualenv environment integration. Other IDEs have not been studied yet, and integration is also very convenient:
(1) Create a new project
(2) Click the settings icon in the interpreter bar
(3) Select virtualenv
(4) You can create a new one or select an existing virtualenv environment
After configuring, we can also test it in this project, select an installation module that is different from the system environment, and check whether its version is correct. I have 2 django here. version, so I used the django module to test and got the correct results.
For more articles related to installing Virtualenv on Windows to create an independent Python environment, please pay attention to the PHP Chinese website!

TomergelistsinPython,youcanusethe operator,extendmethod,listcomprehension,oritertools.chain,eachwithspecificadvantages:1)The operatorissimplebutlessefficientforlargelists;2)extendismemory-efficientbutmodifiestheoriginallist;3)listcomprehensionoffersf

In Python 3, two lists can be connected through a variety of methods: 1) Use operator, which is suitable for small lists, but is inefficient for large lists; 2) Use extend method, which is suitable for large lists, with high memory efficiency, but will modify the original list; 3) Use * operator, which is suitable for merging multiple lists, without modifying the original list; 4) Use itertools.chain, which is suitable for large data sets, with high memory efficiency.

Using the join() method is the most efficient way to connect strings from lists in Python. 1) Use the join() method to be efficient and easy to read. 2) The cycle uses operators inefficiently for large lists. 3) The combination of list comprehension and join() is suitable for scenarios that require conversion. 4) The reduce() method is suitable for other types of reductions, but is inefficient for string concatenation. The complete sentence ends.

PythonexecutionistheprocessoftransformingPythoncodeintoexecutableinstructions.1)Theinterpreterreadsthecode,convertingitintobytecode,whichthePythonVirtualMachine(PVM)executes.2)TheGlobalInterpreterLock(GIL)managesthreadexecution,potentiallylimitingmul

Key features of Python include: 1. The syntax is concise and easy to understand, suitable for beginners; 2. Dynamic type system, improving development speed; 3. Rich standard library, supporting multiple tasks; 4. Strong community and ecosystem, providing extensive support; 5. Interpretation, suitable for scripting and rapid prototyping; 6. Multi-paradigm support, suitable for various programming styles.

Python is an interpreted language, but it also includes the compilation process. 1) Python code is first compiled into bytecode. 2) Bytecode is interpreted and executed by Python virtual machine. 3) This hybrid mechanism makes Python both flexible and efficient, but not as fast as a fully compiled language.

Useaforloopwheniteratingoverasequenceorforaspecificnumberoftimes;useawhileloopwhencontinuinguntilaconditionismet.Forloopsareidealforknownsequences,whilewhileloopssuitsituationswithundeterminediterations.

Pythonloopscanleadtoerrorslikeinfiniteloops,modifyinglistsduringiteration,off-by-oneerrors,zero-indexingissues,andnestedloopinefficiencies.Toavoidthese:1)Use'i


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
