Pipenv Shell中出现ModuleNotFoundError吗?

时间:2018-07-05 22:37:19

标签: python pipenv

我正在处理的Python项目从使用virtualenvrequirements.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的{​​{1}}:

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?还是我需要执行其他步骤?

2 个答案:

答案 0 :(得分:0)

事实证明,您确实需要运行pipenv install才能真正安装软件包。 pipenv shell命令仅激活虚拟环境。

答案 1 :(得分:0)

尝试改用虚拟环境。

python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt