Home > Article > Backend Development > How to create a virtual environment with pipenv
Pipenv Steps to create a virtual environment: 1. Make sure pipenv is installed; 2. Open a terminal or command line interface and navigate to the project directory; 3. Run the "pipenv --venv" command in the project directory to create a virtual environment; 4. Activate the virtual environment. After activation, you will see the command line prompt prefix with "venv" added; 5. The virtual environment is successfully created and activated, and the dependencies of the project can be installed and managed in it; 6. When you have finished your work and want to exit the virtual environment, you can run the "deactivate" command.
Operating system for this tutorial: Windows 10 system, Python version 3.11.4, Dell G3 computer.
pipenv is a Python dependency management tool that can help developers manage project dependencies and create virtual environments to isolate the dependencies of different projects. The following are the steps to create a virtual environment using pipenv:
1. Make sure pipenv is installed. If it is not installed, you can install it using the following command:
pip install pipenv
2. Open a terminal or command line interface and navigate to your project directory.
3. Run the following command in the project directory to create a virtual environment:
pipenv --venv
After running this command, pipenv will create a file named .venv directory that contains all the dependencies of the virtual environment.
4. Now you can activate the virtual environment. On Windows, run the following command:
venv\Scripts\activate.bat
On macOS and Linux, run the following command:
source venv/bin/activate
Once you activate the virtual environment, you will see the command line prompt prefix increase (venv), indicating that a virtual environment is currently being used.
5. Now that you have successfully created and activated your virtual environment, you can install and manage your project's dependencies. For example, use the following command to install dependencies:
pipenv install <package-name>
6. When you have finished your work and want to exit the virtual environment , you can run the following command:
deactivate
This will exit the virtual environment and return to the system's default Python environment.
The above is the detailed content of How to create a virtual environment with pipenv. For more information, please follow other related articles on the PHP Chinese website!