In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use virtualenv in python virtual environment". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn how to use virtualenv in python virtual environment.
What is virtualenv?
Virtualenv is a tool for creating an isolated Python environment.
Why create a virtual environment?
It solves the dilemma that Project X depends on version 1.x, while Project Y requires Project 4.x, and keeps your global site-packages catalog clean and manageable.
Brief introduction
Isolate different python environments, such as some projects use Django1.11 and some projects use Django2.0. In order to prevent repeated reinstallation of different versions of Django in the global environment, two virtual environments can be used.
This not only ensures the isolation between the two environments, but also does not pollute the overall environment and ensures the cleanliness of the global environment.
Install the virtualenv module
$pip3 install virtualenv-I https://pypi.tuna.tsinghua.edu.cn/simple/
Create a virtual environment
To the path where you want to create the virtual environment, execute the following command to install
$virtualenv envname # create a virtual environment named envname $virtualenv-p python2 envname # if you have installed multiple versions of python, such as py2 and py3, you need to specify which one to use to create the virtual environment
Start and stop virtual environment
# enter the virtual environment file cd envname# and enter the relevant startup folder cd Scriptsactivate # launch the virtual environment deactivate # exit the virtual environment
Operation in virtual environment
# View the current python version in the virtual environment python-V# View the current pip version in the virtual environment pip-V# View the module installed in the current virtual environment pip list# install the module pip install module_name in the virtual environment
The default path for modules installed in a virtual environment is as follows
$Virtual environment path\ Lib\ site-packages\
Pycharm references the virtual environment
When you directly select the interpreter in pycharm, you can select the python interpreter in this virtual environment.
If pycharm directly opens the folder of the virtual environment, the virtual environment will be active (can be confirmed in the Terminal of pycharm)
How to create a Django project through this virtual environment
Change to the newly created virtual environment directory and activate the virtual environment
Within the virtual environment (active), executing django-admin startproject Project_name. Will create a new folder for the Django project under the current virtual environment root.
Delete virtual environment
Just delete the folder.
Virtualenvwrapper
The native virtualenv module is slightly cumbersome in the operation of the virtual environment. Virtualenvwrapper is the encapsulated version of it, which makes it much more convenient to operate, such as deleting a virtual environment through rmvirtualenv venvName.
Pip install virtualenvwrapper # this is the encapsulated version of virtualenv, be sure to install the above after virtualenv is all the content of this article "how to use virtualenv in python virtual environment", thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.