用诗歌安装 Django 后,它在活动的 venv 中说 "No module named django"
After installing Django with poetry it says "No module named django" in active venv
我正在玩 poetry
因为我正在考虑从 pip
切换。
在 basic usage examples 之后,我正在执行以下操作:
$ poetry new poetry-demo
$ cd poetry-demo
$ poetry add django
$ django-admin #can't find it
$ poetry shell #or poetry $(poetry env info --path)/bin/activate
$ django-admin
Traceback (most recent call last):
File "/Users/cjones/Library/Caches/pypoetry/virtualenvs/poetry-demo-Jq168aNm-py3.8/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
也试过这个顺序:
$ poetry new poetry-demo
$ cd poetry-demo
$ poetry shell #or poetry $(poetry env info --path)/bin/activate
$ poetry add django
$ django-admin
Traceback (most recent call last):
File "/Users/cjones/Library/Caches/pypoetry/virtualenvs/poetry-demo-Jq168aNm-py3.8/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
勾选 pyproject.toml
:
[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.8"
Django = "^3.2.6"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
检查poetry show
:
asgiref 3.4.1 ASGI specs, helper code, and adapters
attrs 21.2.0 Classes Without Boilerplate
django 3.2.6 A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
more-itertools 8.8.0 More routines for operating on iterables, beyond itertools
packaging 21.0 Core utilities for Python packages
pluggy 0.13.1 plugin and hook calling mechanisms for python
py 1.10.0 library with cross-python path, ini-parsing, io, code, log facilities
pyparsing 2.4.7 Python parsing module
pytest 5.4.3 pytest: simple powerful testing with Python
pytz 2021.1 World timezone definitions, modern and historical
sqlparse 0.4.1 A non-validating SQL parser.
wcwidth 0.2.5 Measures the displayed width of unicode strings in a terminal
检查它说它不存在的路径,它就在那里:
$ ls -l $(poetry env info --path)/bin
total 144
-rw-r--r-- 1 cjones staff 2197 Aug 27 09:39 activate
-rw-r--r-- 1 cjones staff 1489 Aug 27 09:39 activate.csh
-rw-r--r-- 1 cjones staff 3120 Aug 27 09:39 activate.fish
-rw-r--r-- 1 cjones staff 1751 Aug 27 09:39 activate.ps1
-rw-r--r-- 1 cjones staff 1199 Aug 27 09:39 activate_this.py
-rwxr-xr-x 1 cjones staff 339 Aug 27 09:39 django-admin
-rwxr-xr-x 1 cjones staff 729 Aug 27 09:39 django-admin.py
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip-3.8
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip3
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip3.8
-rwxr-xr-x 1 cjones staff 281 Aug 27 09:39 py.test
-rwxr-xr-x 1 cjones staff 281 Aug 27 09:39 pytest
lrwxr-xr-x 1 cjones staff 128 Aug 27 09:39 python -> /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
lrwxr-xr-x 1 cjones staff 6 Aug 27 09:39 python3 -> python
lrwxr-xr-x 1 cjones staff 6 Aug 27 09:39 python3.8 -> python
-rwxr-xr-x 1 cjones staff 292 Aug 27 09:39 sqlformat
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel-3.8
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel3
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel3
停用并反应 venv
。我重新启动了 shell。仍然只是得到:
Traceback (most recent call last):
File "/Users/cjones/Library/Caches/pypoetry/virtualenvs/poetry-demo-Jq168aNm-py3.8/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
关于这里的问题以及如何解决的建议?
应该更仔细地阅读这篇文章:
https://python-poetry.org/docs/basic-usage/#using-poetry-run
poetry run django-admin
我正在玩 poetry
因为我正在考虑从 pip
切换。
在 basic usage examples 之后,我正在执行以下操作:
$ poetry new poetry-demo
$ cd poetry-demo
$ poetry add django
$ django-admin #can't find it
$ poetry shell #or poetry $(poetry env info --path)/bin/activate
$ django-admin
Traceback (most recent call last):
File "/Users/cjones/Library/Caches/pypoetry/virtualenvs/poetry-demo-Jq168aNm-py3.8/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
也试过这个顺序:
$ poetry new poetry-demo
$ cd poetry-demo
$ poetry shell #or poetry $(poetry env info --path)/bin/activate
$ poetry add django
$ django-admin
Traceback (most recent call last):
File "/Users/cjones/Library/Caches/pypoetry/virtualenvs/poetry-demo-Jq168aNm-py3.8/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
勾选 pyproject.toml
:
[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.8"
Django = "^3.2.6"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
检查poetry show
:
asgiref 3.4.1 ASGI specs, helper code, and adapters
attrs 21.2.0 Classes Without Boilerplate
django 3.2.6 A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
more-itertools 8.8.0 More routines for operating on iterables, beyond itertools
packaging 21.0 Core utilities for Python packages
pluggy 0.13.1 plugin and hook calling mechanisms for python
py 1.10.0 library with cross-python path, ini-parsing, io, code, log facilities
pyparsing 2.4.7 Python parsing module
pytest 5.4.3 pytest: simple powerful testing with Python
pytz 2021.1 World timezone definitions, modern and historical
sqlparse 0.4.1 A non-validating SQL parser.
wcwidth 0.2.5 Measures the displayed width of unicode strings in a terminal
检查它说它不存在的路径,它就在那里:
$ ls -l $(poetry env info --path)/bin
total 144
-rw-r--r-- 1 cjones staff 2197 Aug 27 09:39 activate
-rw-r--r-- 1 cjones staff 1489 Aug 27 09:39 activate.csh
-rw-r--r-- 1 cjones staff 3120 Aug 27 09:39 activate.fish
-rw-r--r-- 1 cjones staff 1751 Aug 27 09:39 activate.ps1
-rw-r--r-- 1 cjones staff 1199 Aug 27 09:39 activate_this.py
-rwxr-xr-x 1 cjones staff 339 Aug 27 09:39 django-admin
-rwxr-xr-x 1 cjones staff 729 Aug 27 09:39 django-admin.py
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip-3.8
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip3
-rwxr-xr-x 1 cjones staff 297 Aug 27 09:39 pip3.8
-rwxr-xr-x 1 cjones staff 281 Aug 27 09:39 py.test
-rwxr-xr-x 1 cjones staff 281 Aug 27 09:39 pytest
lrwxr-xr-x 1 cjones staff 128 Aug 27 09:39 python -> /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
lrwxr-xr-x 1 cjones staff 6 Aug 27 09:39 python3 -> python
lrwxr-xr-x 1 cjones staff 6 Aug 27 09:39 python3.8 -> python
-rwxr-xr-x 1 cjones staff 292 Aug 27 09:39 sqlformat
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel-3.8
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel3
-rwxr-xr-x 1 cjones staff 284 Aug 27 09:39 wheel3
停用并反应 venv
。我重新启动了 shell。仍然只是得到:
Traceback (most recent call last):
File "/Users/cjones/Library/Caches/pypoetry/virtualenvs/poetry-demo-Jq168aNm-py3.8/bin/django-admin", line 5, in <module>
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
关于这里的问题以及如何解决的建议?
应该更仔细地阅读这篇文章:
https://python-poetry.org/docs/basic-usage/#using-poetry-run
poetry run django-admin