search
HomeBackend DevelopmentPython TutorialCreating a virtual environment: Getting started quickly with pipenv
Creating a virtual environment: Getting started quickly with pipenvJan 16, 2024 am 11:08 AM
virtual environmentpipenvGetting Started Guide

Creating a virtual environment: Getting started quickly with pipenv

Get started with pipenv quickly: Create your first virtual environment

In Python development, using virtual environments is a common practice, which can help us isolate Conflicts between projects and dependent packages allow projects to run independently. Pipenv is a Python package management tool that integrates the functions of virtual environment and dependent package management, which can simplify our development process and environment configuration. This article will introduce how to quickly get started with pipenv and create your first virtual environment.

1. Install pipenv

To use pipenv, you first need to install it. You can use pip to install and run the following command in the terminal:

$ pip install pipenv

After the installation is successful, you can verify whether pipenv is installed normally by running the following command:

$ pipenv --version

If pipenv can be displayed correctly Version information indicates successful installation.

2. Create a virtual environment

Now we start to create the first virtual environment. Enter your project directory on the command line and run the following command:

$ pipenv shell

After running the above command, pipenv will automatically create a new virtual environment and switch your terminal to that environment. You will find that the terminal prompt has changed, indicating that you have entered the virtual environment.

3. Install dependency packages

After we have a virtual environment, we can use pipenv to install and manage the project's dependency packages. Run the following command in the terminal to install a sample dependency package (such as requests):

$ pipenv install requests

After running the above command, pipenv will automatically download and install the dependency package, and generate a file named in the project directory. Pipfile file, which records the project’s dependency package information.

In addition to using the pipenv install command to install a single dependency package, you can also use the pipenv install -r requirements.txt command to install a requirements.txt Install dependent packages in batches from files.

4. Run the Python script

Now, we can run the Python script in the virtual environment. Create a file named main.py in the project directory with the following content:

import requests

response = requests.get('https://www.python.org')
print(response.status_code)

After saving and exiting the file, run the following command in the terminal to execute the script:

$ python main.py

The running result will output the status code of the target website.

5. Exit the virtual environment

When you have completed the development of the current project, you can exit the virtual environment. Run the following command in the terminal:

$ exit

After running the above command, you will exit the virtual environment and return to the original environment.

Summary:

Through the above steps, you have successfully created and used your first virtual environment. pipenv provides simple commands to manage project dependency packages, making our development process more efficient and convenient. I hope this article can help you get started with pipenv quickly and bring its value into play in future development.

The above is the detailed content of Creating a virtual environment: Getting started quickly with pipenv. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
pycharm如何配置虚拟环境pycharm如何配置虚拟环境Dec 08, 2023 pm 05:45 PM

pycharm配置虚拟环境的步骤:1、打开PyCharm,进入“File”菜单,选择“Settings”;2、在设置窗口中,展开“Project”节点,然后选择“Project Interpreter”;3、点击右上角的“+”图标,在弹出的窗口中选择“Virtualenv Environment”;4、在“Name”字段中输入虚拟环境的名称,在“Location”字段中等等。

利用conda建立可靠且持久的Python虚拟环境利用conda建立可靠且持久的Python虚拟环境Feb 19, 2024 pm 09:25 PM

使用conda构建稳定可靠的Python虚拟环境,需要具体代码示例随着Python的飞速发展,越来越多的开发者需要在不同的项目中使用不同版本的Python以及各种依赖库。而多个项目共享同一个Python环境可能会导致版本冲突等问题,为了解决这些问题,使用虚拟环境是一个很好的选择。而conda是一个非常受欢迎的虚拟环境管理工具,它可以帮助我们创建、管理多个稳定

pycharm怎么创建虚拟环境pycharm怎么创建虚拟环境Dec 11, 2023 am 09:22 AM

PyCharm创建虚拟环境需通过以下8个步骤完成:1、打开PyCharm进入项目;2、菜单栏中选择 "File" ,"Settings";3、设置窗口中选择 "Python Interpreter";4、下拉菜单中选择 "Show All…";5、点击 "Add" 图标;6、选择 "Virtualenv”点击”ok“;7、选择虚拟环境的位置和解释器版本;8、自动创建虚拟环境。

学习使用pipenv:创建和管理虚拟环境学习使用pipenv:创建和管理虚拟环境Jan 16, 2024 am 09:34 AM

pipenv教程:创建和管理虚拟环境,需要具体代码示例介绍:随着Python的流行,项目开发数量也在不断增加。为了有效地管理项目中所使用的Python包,虚拟环境成为了必不可少的工具。在本文中,我们将介绍如何使用pipenv来创建和管理虚拟环境,并提供实际的代码示例。什么是pipenv?pipenv是Python社区广泛使用的一种虚拟环境管理工具。它整合了p

掌握conda虚拟环境的优点及操作技巧掌握conda虚拟环境的优点及操作技巧Feb 18, 2024 pm 07:46 PM

了解conda虚拟环境的优势与使用技巧,需要具体代码示例Python是一门非常流行的编程语言,广泛应用于科学计算、数据分析和人工智能等领域。在Python的生态系统中,有许多第三方库和工具,在不同的项目中可能需要使用不同版本的库。为了管理这些库的依赖关系,conda虚拟环境成为了一个重要的工具。conda是一个开源的包管理系统和环境管理系统,能够方便地创建和

pycharm怎么配置虚拟环境pycharm怎么配置虚拟环境Dec 08, 2023 pm 04:51 PM

pycharm配置虚拟环境步骤:1、打开PyCharm,选择File -> Settings来打开设置对话框;2、在设置对话框中,展开Project: [Your Project Name],然后选择Python Interpreter;3、点击右上角的齿轮图标,选择Add…来添加一个新的虚拟环境即可。

从头开始:学会使用conda创建虚拟环境的基础技能从头开始:学会使用conda创建虚拟环境的基础技能Jan 04, 2024 pm 01:35 PM

从零开始:掌握conda创建虚拟环境的基本技巧引言:在进行Python开发和数据分析的过程中,创建虚拟环境是一个必备的技巧。虚拟环境可以帮助我们隔离不同项目的依赖关系,避免版本冲突和依赖混乱。而conda作为一个强大的包管理工具,可以帮助我们轻松地创建和管理虚拟环境。本文将介绍如何使用conda从零开始创建虚拟环境,并提供了具体的代码示例。第一步:安装con

深入解析conda虚拟环境的管理方法:创建、激活和删除的全面指南深入解析conda虚拟环境的管理方法:创建、激活和删除的全面指南Jan 04, 2024 pm 04:37 PM

如何管理conda虚拟环境:创建、激活和删除的方法详解概述在数据科学和机器学习领域,我们经常需要使用不同的软件包和库,而这些软件包和库可能存在不同的版本之间的冲突。为了解决这个问题,我们可以使用conda来创建和管理虚拟环境。本文将详细介绍如何使用conda在Python中创建、激活和删除虚拟环境,并提供具体的代码示例。创建虚拟环境首先,我们需要安装cond

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

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.