首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >琵琶壳中的ModuleNotFoundError?

琵琶壳中的ModuleNotFoundError?
EN

Stack Overflow用户
提问于 2018-07-05 22:37:19
回答 2查看 1.5K关注 0票数 1

我最近正在从事的一个Python项目从使用带有virtualenvrequirements.txt切换到使用pipenv。根目录包含以下Pipfile

代码语言:javascript
复制
[[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

代码语言:javascript
复制
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,我得到了一个dotenvModuleNotFoundError

代码语言:javascript
复制
(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命令,就不会看到安装了任何包:

代码语言:javascript
复制
(lucy-web-CVxkrCFK) bash-3.2$ pip freeze
(lucy-web-CVxkrCFK) bash-3.2$ 

pipenv shell是否应该已经在Pipfile中安装了packages?还是我需要做一个额外的步骤?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-07-05 22:59:14

实际上,您确实需要运行pipenv install才能实际安装这些包。pipenv shell命令只激活虚拟环境。

票数 0
EN

Stack Overflow用户

发布于 2020-01-16 12:34:45

尝试使用虚拟env代替。

代码语言:javascript
复制
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51200765

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档