After installing Django with poetry it says "No module named django" in active venv

cjones

I'm playing with poetry because I'm thinking about switching from pip.

Following the basic usage examples, I'm doing the following:

$ 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'

Also tried in this order:

$ 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'

Check the pyproject.toml:

[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]

[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"

Check 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

Check the path where it says it is not and there it is:

$ 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

Deactivate and reactive the venv. I've restarted the shell. Still just get:

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'

Suggestions for what is up here and how to resolve it?

cjones

Should have read this more closely:

https://python-poetry.org/docs/basic-usage/#using-poetry-run

poetry run django-admin

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

import django ModuleNotFoundError: No module named 'django' after install python 2

ModuleNotFoundError: No module named 'django'

django, pyenv, uwsgi - ModuleNotFoundError: No module named 'django'

Import Error: No module named django - for specific project

ModuleNotFoundError: No module named 'django' problem in vs code

Error running WSGI application, no module named django

Python not recognising Django Installation. (ImportError: No module named django)

Running django-admin tutorial erros: no module named django

Python manage.py ImportError: No module named django

ModuleNotFoundError: No module named 'django' while running server in virtual environment

Apache with virtualenv and mod_wsgi : ImportError : No module named 'django'

ModuleNotFoundError: No module named 'django' when deploying to Elastic Beanstalk

django/apache can't serve webpage within Docker Container. Error - ModuleNotFoundError: No module named 'django'

ImportError: No module named 'django' uWSGI Django Nginx Ubuntu 16.04 Python3.6

500 internal server error mod_wsgi apache "importerror: No Module named 'django'

Target WSGI script cannot be loaded as a python module and ImportError: No module named 'django'

Python 3 Upgrade: uninstall/reinstall 3.6-3.7 — Now I cannot install Django 2.1: Error msg: [ No module named Django ]

Installing Poetry fails on Docker

Installing kivy in venv on Ubuntu

How to specify which python version poetry should create venv?

Pip not installing during virtualenv venv

Installing a python project using Poetry in a Docker container

Invalid active developer path on MAC OS X after installing Ruby

Restart immediately after installing Windows updates, regardless of active hours

Django - Migrate command says that table exists after second makemigrations was executed

Django servers not starting after installing live server

Django - ImportError after Installing Angular and React

Laptop won't boot; says "BOOTMGR is missing" after active partition was changed

Installing venv for python3 in WSL (Ubuntu)