下面是一个shell会话,演示了以下步骤:
dotenv
对Python不可用dotenv
中的requirements.txt
不是 pip install -r requirements.txt
dotenv
可用于Python dotenv
列出的pip freeze
不是 这怎么可能?
$ python -m venv venv
$ activate
(venv) $ python
Python 3.7.3 (default, Mar 27 2019, 09:23:15)
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> dotenv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'dotenv' is not defined
>>> exit()
(venv) $ cat requirements.txt
alembic==1.0.8
bcrypt==3.1.6
blinker==1.4
cffi==1.12.2
Click==7.0
dominate==2.3.5
entrypoints==0.3
flake8==3.7.7
Flask==1.0.2
Flask-Bcrypt==0.7.1
Flask-Bootstrap==3.3.7.1
Flask-DebugToolbar==0.10.1
Flask-DotEnv==0.1.1
Flask-Login==0.4.1
Flask-Migrate==2.4.0
Flask-SQLAlchemy==2.3.2
Flask-Testing==0.7.1
Flask-WTF==0.14.2
itsdangerous==1.1.0
Jinja2==2.10.1
Mako==1.0.8
MarkupSafe==1.1.1
mccabe==0.6.1
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
python-dateutil==2.8.0
python-dotenv==0.10.1
python-editor==1.0.4
six==1.12.0
SQLAlchemy==1.3.2
visitor==0.1.3
Werkzeug==0.15.2
WTForms==2.2.1
(venv) $ pip install -r requirements.txt
Collecting alembic==1.0.8 (from -r requirements.txt (line 1))
Collecting bcrypt==3.1.6 (from -r requirements.txt (line 2))
Using cached https://files.pythonhosted.org/packages/c8/05/e51ab21c47981eb554a94a7b5af9e61f82640dec99713cd3b359c91ff39e/bcrypt-3.1.6-cp34-abi3-macosx_10_6_intel.whl
Collecting blinker==1.4 (from -r requirements.txt (line 3))
Collecting cffi==1.12.2 (from -r requirements.txt (line 4))
Using cached https://files.pythonhosted.org/packages/6b/af/e39e89ecbfb676c6aa5855b1795bb207f4005187495c8d40e26b5fb51bfa/cffi-1.12.2-cp37-cp37m-macosx_10_9_x86_64.whl
Collecting Click==7.0 (from -r requirements.txt (line 5))
Using cached https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
Collecting dominate==2.3.5 (from -r requirements.txt (line 6))
Using cached https://files.pythonhosted.org/packages/1a/54/50ec03a4b4114e2c02d049cc26fe6ad8f0653ba5d0cd55d7c9bf9a260434/dominate-2.3.5-py2.py3-none-any.whl
Collecting entrypoints==0.3 (from -r requirements.txt (line 7))
Using cached https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl
Collecting flake8==3.7.7 (from -r requirements.txt (line 8))
Using cached https://files.pythonhosted.org/packages/e9/76/b915bd28976068a9843bf836b789794aa4a8eb13338b23581005cd9177c0/flake8-3.7.7-py2.py3-none-any.whl
Collecting Flask==1.0.2 (from -r requirements.txt (line 9))
Using cached https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl
Collecting Flask-Bcrypt==0.7.1 (from -r requirements.txt (line 10))
Collecting Flask-Bootstrap==3.3.7.1 (from -r requirements.txt (line 11))
Collecting Flask-DebugToolbar==0.10.1 (from -r requirements.txt (line 12))
Using cached https://files.pythonhosted.org/packages/c9/3c/309073df635148f3536a5ed67940fb9b51ca67c1d6d2debafb81533201f3/Flask_DebugToolbar-0.10.1-py2.py3-none-any.whl
Collecting Flask-DotEnv==0.1.1 (from -r requirements.txt (line 13))
Collecting Flask-Login==0.4.1 (from -r requirements.txt (line 14))
Collecting Flask-Migrate==2.4.0 (from -r requirements.txt (line 15))
Using cached https://files.pythonhosted.org/packages/07/6a/53695aab4c7cf7b230e46a5e4f06e0c9719c01a51223590fd75804439a01/Flask_Migrate-2.4.0-py2.py3-none-any.whl
Collecting Flask-SQLAlchemy==2.3.2 (from -r requirements.txt (line 16))
Using cached https://files.pythonhosted.org/packages/a1/44/294fb7f6bf49cc7224417cd0637018db9fee0729b4fe166e43e2bbb1f1c8/Flask_SQLAlchemy-2.3.2-py2.py3-none-any.whl
Collecting Flask-Testing==0.7.1 (from -r requirements.txt (line 17))
Collecting Flask-WTF==0.14.2 (from -r requirements.txt (line 18))
Using cached https://files.pythonhosted.org/packages/60/3a/58c629472d10539ae5167dc7c1fecfa95dd7d0b7864623931e3776438a24/Flask_WTF-0.14.2-py2.py3-none-any.whl
Collecting itsdangerous==1.1.0 (from -r requirements.txt (line 19))
Using cached https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Jinja2==2.10.1 (from -r requirements.txt (line 20))
Using cached https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl
Collecting Mako==1.0.8 (from -r requirements.txt (line 21))
Collecting MarkupSafe==1.1.1 (from -r requirements.txt (line 22))
Using cached https://files.pythonhosted.org/packages/ce/c6/f000f1af136ef74e4a95e33785921c73595c5390403f102e9b231b065b7a/MarkupSafe-1.1.1-cp37-cp37m-macosx_10_6_intel.whl
Collecting mccabe==0.6.1 (from -r requirements.txt (line 23))
Using cached https://files.pythonhosted.org/packages/87/89/479dc97e18549e21354893e4ee4ef36db1d237534982482c3681ee6e7b57/mccabe-0.6.1-py2.py3-none-any.whl
Collecting pycodestyle==2.5.0 (from -r requirements.txt (line 24))
Using cached https://files.pythonhosted.org/packages/0e/0c/04a353e104d2f324f8ee5f4b32012618c1c86dd79e52a433b64fceed511b/pycodestyle-2.5.0-py2.py3-none-any.whl
Collecting pycparser==2.19 (from -r requirements.txt (line 25))
Collecting pyflakes==2.1.1 (from -r requirements.txt (line 26))
Using cached https://files.pythonhosted.org/packages/84/f2/ed0ffb887f8138a8fe5a621b8c0bb9598bfb3989e029f6c6a85ee66628ee/pyflakes-2.1.1-py2.py3-none-any.whl
Collecting python-dateutil==2.8.0 (from -r requirements.txt (line 27))
Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting python-dotenv==0.10.1 (from -r requirements.txt (line 28))
Using cached https://files.pythonhosted.org/packages/8c/14/501508b016e7b1ad0eb91bba581e66ad9bfc7c66fcacbb580eaf9bc38458/python_dotenv-0.10.1-py2.py3-none-any.whl
Collecting python-editor==1.0.4 (from -r requirements.txt (line 29))
Using cached https://files.pythonhosted.org/packages/c6/d3/201fc3abe391bbae6606e6f1d598c15d367033332bd54352b12f35513717/python_editor-1.0.4-py3-none-any.whl
Collecting six==1.12.0 (from -r requirements.txt (line 30))
Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting SQLAlchemy==1.3.2 (from -r requirements.txt (line 31))
Collecting visitor==0.1.3 (from -r requirements.txt (line 32))
Collecting Werkzeug==0.15.2 (from -r requirements.txt (line 33))
Using cached https://files.pythonhosted.org/packages/18/79/84f02539cc181cdbf5ff5a41b9f52cae870b6f632767e43ba6ac70132e92/Werkzeug-0.15.2-py2.py3-none-any.whl
Collecting WTForms==2.2.1 (from -r requirements.txt (line 34))
Using cached https://files.pythonhosted.org/packages/9f/c8/dac5dce9908df1d9d48ec0e26e2a250839fa36ea2c602cc4f85ccfeb5c65/WTForms-2.2.1-py2.py3-none-any.whl
Installing collected packages: python-editor, six, python-dateutil, MarkupSafe, Mako, SQLAlchemy, alembic, pycparser, cffi, bcrypt, blinker, Click, dominate, entrypoints, pyflakes, pycodestyle, mccabe, flake8, Werkzeug, itsdangerous, Jinja2, Flask, Flask-Bcrypt, visitor, Flask-Bootstrap, Flask-DebugToolbar, Flask-DotEnv, Flask-Login, Flask-SQLAlchemy, Flask-Migrate, Flask-Testing, WTForms, Flask-WTF, python-dotenv
Successfully installed Click-7.0 Flask-1.0.2 Flask-Bcrypt-0.7.1 Flask-Bootstrap-3.3.7.1 Flask-DebugToolbar-0.10.1 Flask-DotEnv-0.1.1 Flask-Login-0.4.1 Flask-Migrate-2.4.0 Flask-SQLAlchemy-2.3.2 Flask-Testing-0.7.1 Flask-WTF-0.14.2 Jinja2-2.10.1 Mako-1.0.8 MarkupSafe-1.1.1 SQLAlchemy-1.3.2 WTForms-2.2.1 Werkzeug-0.15.2 alembic-1.0.8 bcrypt-3.1.6 blinker-1.4 cffi-1.12.2 dominate-2.3.5 entrypoints-0.3 flake8-3.7.7 itsdangerous-1.1.0 mccabe-0.6.1 pycodestyle-2.5.0 pycparser-2.19 pyflakes-2.1.1 python-dateutil-2.8.0 python-dotenv-0.10.1 python-editor-1.0.4 six-1.12.0 visitor-0.1.3
(venv) $ python
Python 3.7.3 (default, Mar 27 2019, 09:23:15)
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dotenv
>>> dotenv
<module 'dotenv' from '/Users/chuck/.../venv/lib/python3.7/site-packages/dotenv/__init__.py'>
>>> exit()
(venv) $ pip freeze
alembic==1.0.8
bcrypt==3.1.6
blinker==1.4
cffi==1.12.2
Click==7.0
dominate==2.3.5
entrypoints==0.3
flake8==3.7.7
Flask==1.0.2
Flask-Bcrypt==0.7.1
Flask-Bootstrap==3.3.7.1
Flask-DebugToolbar==0.10.1
Flask-DotEnv==0.1.1
Flask-Login==0.4.1
Flask-Migrate==2.4.0
Flask-SQLAlchemy==2.3.2
Flask-Testing==0.7.1
Flask-WTF==0.14.2
itsdangerous==1.1.0
Jinja2==2.10.1
Mako==1.0.8
MarkupSafe==1.1.1
mccabe==0.6.1
pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
python-dateutil==2.8.0
python-dotenv==0.10.1
python-editor==1.0.4
six==1.12.0
SQLAlchemy==1.3.2
visitor==0.1.3
Werkzeug==0.15.2
WTForms==2.2.1
答案 0 :(得分:1)
您的requirements.txt
确实列出它:
python-dotenv==0.10.1
Python项目的名称不必与它们的内容相同。 python-dotenv
安装dotenv
软件包。 Python项目可以包含多个顶层模块或包,因此强制实施这样的限制是没有道理的。
请参见https://localhost:8080/test2:
将以下代码添加到您的
settings.py
# settings.py from dotenv import load_dotenv load_dotenv()