Django tutorial: `python startapp polls` fails

Trying the official tutorial, using Catalina 10.15.5, python 3.8.3 and django 3.0.6, is failing with:

TypeError: argument of type 'PosixPath' is not iterable

Absolute beginner with Django, couldn’t find much help with searches.

Where at within the official tutorial are you receiving this message?
(What command is generating this message and what step are you on?)

1 Like

From here, everything was successful until I got to this section.

The traceback is:
Traceback (most recent call last):

File “”, line 22, in
File “”, line 18, in main
File “/Users/bobrien/.pyenv/versions/”, line 401, in execute_from_command_line
File “/Users/bobrien/.pyenv/versions/”, line 395, in execute
File “/Users/bobrien/.pyenv/versions/”, line 341, in run_from_argv
File “/Users/bobrien/.pyenv/versions/”, line 230, in close_all
File “/Users/bobrien/.pyenv/versions/”, line 26, in inner
return func(*args, **kwargs)
File “/Users/bobrien/.pyenv/versions/”, line 261, in close
if not self.is_in_memory_db():
File “/Users/bobrien/.pyenv/versions/”, line 380, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict[‘NAME’])
File “/Users/bobrien/.pyenv/versions/”, line 12, in is_in_memory_db
return database_name == ‘:memory:’ or ‘mode=memory’ in database_name
TypeError: argument of type ‘PosixPath’ is not iterable

I think you’ve somehow used Django 3.1’s startproject template. Django 3.1 moved the BASE_DIR pseudo-setting to use pathlib.Path rather than a plain string. Support for this needed adding to some places like the sqlite driver, so it doesn’t work there.

If you look at the definition of BASE_DIR in your settings file, is it using a Path() ? If so you can use str() around its use in your DATABASES setting, i.e. str(BASE_DIR / "something.sqlite").

I covered this change more in a blog post: Use Pathlib in Your Django Settings File

Hope that helps


@adamchainz @KenWhitesell
Thank you both for your help.
I deactivated my virtualenv and got past this error.
Now, I’m into the actual polls app - and can see both /polls and /admin, but getting a 404 when I try to access :joy:

Please note: I’m not asking for help on my new issue in this thread. I’ll open a new topic if I can’t figure this one out.

Again, thank you from a Django beginner!

@bryanmobrien that’s expected. There is no URL mapped at the root, only the index at polls/ and the admin at admin/, so you should see Django’s yellow debug 404 page when visiting the root URL.

Thank you! I assumed I fat-fingered or settings.
Moving forward! :crazy_face:

I had the same problem as the original poster and your solution worked! Thanks for your help

Thanks a lot. Your suggestion was really helpful to solve this problem I also ran into.

Your solution solve my problem thanks, but just I want to inform that this change need to be in the file
the path: /your_project/src/mysite