ModuleNotFoundError в оболочке pipenv? - PullRequest
0 голосов
/ 06 июля 2018

Проект Python, над которым я работаю, недавно переключился с использования virtualenv с requirements.txt на использование pipenv. Корневой каталог содержит следующее 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"

Как видите, пакеты включают python-dotenv, который используется в нашем проекте Django manage.py. Однако, если я активирую 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$

и затем попытайтесь запустить python manage.py shell, я получаю ModuleNotFoundError для 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'

Кроме того, если я выполняю команду pip freeze, я не вижу установленных пакетов:

(lucy-web-CVxkrCFK) bash-3.2$ pip freeze
(lucy-web-CVxkrCFK) bash-3.2$ 

Если pipenv shell не имеет packages в Pipfile уже установлен? Или мне нужно сделать дополнительный шаг?

1 Ответ

0 голосов
/ 06 июля 2018

Оказывается, вам действительно нужно запустить pipenv install для фактической установки пакетов. Команда pipenv shell активирует только виртуальную среду.

...