A Python project I'm working on recently switched from using a virtualenv
with a requirements.txt
to using pipenv
. The root directory contains the following Pipfile
:
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
# AWS SDK for Python
boto3 = "==1.6.17"
# Use DATABASE_URL env variable to configure Django application
dj-database-url = "==0.4.2"
# Web framework
django = "==1.11.9"
# Django email integration for transactional ESPs
django-anymail = "==0.10"
# Log of changes made to a model
django-auditlog = "==0.4.5"
# Compresses linked and inline JavaScript or CSS into a single cached file
django-compressor = "==2.2"
# Save and retrieve current request object anywhere in your code
django-crequest = "==2018.5.11"
# Blocks people from brute forcing login attempts
django-defender = "==0.5.4"
# Wrap standard Django fields with encryption
django-encrypted-model-fields = "==0.5.3"
# Custom extensions for the Django Framework
django-extensions = "==2.0.0"
# A set of high-level abstractions for Django forms
django-formtools = "==2.1"
# Import and export data in multiple formats (Excel, CSV, JSON, and so on)
django-import-export = "==0.5.1"
# OAuth2 for Django
django-oauth-toolkit = "==1.0.0"
# SASS integration
django-sass-processor = "==0.5.7"
# Collection of custom storage backends for Django
django-storages = "==1.6.6"
# Two-Factor Authentication for Django
django-two-factor-auth = "==1.7.0"
# Tweak the form field rendering in templates
django-widget-tweaks = "==1.4.1"
# Toolkit for building Web APIs
djangorestframework = "==3.6.3"
# Fixtures replacement
factory-boy = "==2.10.0"
# Style Guide Enforcement
flake8 = "==3.5.0"
# Allows tests to travel through time by mocking the datetime module
freezegun = "==0.3.9"
# Python WSGI HTTP Server
gunicorn = "==19.7.1"
# Newrelic adapter
newrelic = "==2.90.0.75"
# Parsing, formatting, and validating international phone numbers
phonenumbers = "==8.9.1"
# Imaging processing library
pillow = "==5.0.0"
# PostgreSQL adapter
psycopg2 = "==2.7.1"
# Python exception notifier for Airbrake
pybrake = "==0.3.3"
# ISO databases for languages, countries and subdivisions
pycountry = "==18.2.23"
# Extensions to the standard datetime module
python-dateutil = "==2.6.0"
# Loads environment variables from .env file
python-dotenv = "==0.7.1"
# HTTP library
requests = "==2.19.1"
# Python library to capitalize strings
titlecase = "==0.12.0"
# Communication with the Twilio API
twilio = "==6.4.3"
# Static file serving
whitenoise = "==3.3.1"
[dev-packages]
[requires]
python_version = "3.7.0"
As you can see, the packages include python-dotenv
, which is used in our Django project's manage.py
. However, if I activate the pipenv shell
:
Kurts-MacBook-Pro-2:lucy-web kurtpeek$ pipenv shell
Loading .env environment variables...
Creating a virtualenv for this project...
Pipfile: /Users/kurtpeek/Documents/Dev/lucy2/lucy-web/Pipfile
Using /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m (3.7.0) to create virtualenv...
⠋Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
/usr/local/Cellar/pipenv/2018.7.1/libexec/lib/python3.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/bin/python3.7m
Also creating executable in /Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/bin/python
Installing setuptools, pip, wheel...done.
Setting project for lucy-web-CVxkrCFK to /Users/kurtpeek/Documents/Dev/lucy2/lucy-web
Virtualenv location: /Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK
Launching subshell in virtual environment…
bash-3.2$ . /Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/bin/activate
(lucy-web-CVxkrCFK) bash-3.2$
and then try to run python manage.py shell
, I get a ModuleNotFoundError
for dotenv
:
(lucy-web-CVxkrCFK) bash-3.2$ python manage.py shell
Traceback (most recent call last):
File "manage.py", line 4, in <module>
from dotenv import load_dotenv, find_dotenv
ModuleNotFoundError: No module named 'dotenv'
Also, if I do a pip freeze
command I don't see any packages installed:
(lucy-web-CVxkrCFK) bash-3.2$ pip freeze
(lucy-web-CVxkrCFK) bash-3.2$
Should the pipenv shell
not have the packages
in the Pipfile
already installed? Or do I need to do an additional step?
It turns out that you indeed need to run pipenv install
to actually install the packages. The pipenv shell
command only activates the virtual environment.