Summary: in this tutorial, you’ll learn how to install the pipenv
packaging tool on Windows and how to configure a project with a new virtual environment using the Python pipenv
tool.
Prerequisites #
Before installing the pipenv
tool, you need to have Python and pip
installed on your computer.
First, open the Command Prompt or Windows Powershell and type the following command.
python -V
Note that the letter V
in the -V
is uppercase. If you see the Python version like the following:
Python 3.13.2
Code language: CSS (css)
…then you already have Python installed on your computer. Otherwise, you need to install Python first.
Second, use the following command to check if you have the pip
tool on your computer:
pip -V
It’ll return something like this:
pip 25.0.1 from C:\python\Lib\site-packages\pip (python 3.13)
Code language: CSS (css)
Install pipenv on Windows #
First, use the following command to install pipenv
tool:
pip install pipenv
Second, type the following command to check if the pipenv
installed correctly:
pipenv -h
If it shows the following output, then you’ve successfully installed the pipenv
tool successfully.
Usage: pipenv [OPTIONS] COMMAND [ARGS]...
...
Code language: CSS (css)
Creating a new project #
First, create a new project folder e.g., crawler
:
mkdir crawler
cd crawler
Second, navigate to the crawler
folder and install the requests
package using the pipenv
command:
pipenv install requests
You’ll see that pipenv
created two new files called Pipfile
and Pipfile.lock
. On top of that, it installed a virtual environment.
If you look at the project folder, you won’t see the virtual environment folder.
To find the location of the virtual environment, you use the following command:
pipenv --venv
It’ll return something like this on Windows:
C:\Users\<username>\.virtualenvs\crawler-3xu8GCrV
Code language: HTML, XML (xml)
Note that the <username>
is the username that you use to log in to Windows.
Third, activate the new virtual environment using the following command:
pipenv shell
The prompt will change to something like:
(crawler-3xu8GCrV) D:\python_projects\crawler>
Third, create a new file called app.py
in the project folder and add the following code to the file:
import requests
response = requests.get('https://www.python.org/')
print(response.status_code)
Code language: JavaScript (javascript)
In this code, we imported the requests
third-party module, use the get()
function to make an HTTP request to the URL https://www.python.org/
and display the status code (200
).
Fourth, run the app.py
file from the terminal by using the python command:
python app.py
Code language: CSS (css)
It’ll show the following the returned HTTP status code:
200
The status code 200 means the HTTP request has succeeded.
Fifth, close the virtual environment using the exit
command:
exit
Code language: PHP (php)