Windows path object is not iterable

whenever I run the server or executing any commands in the terminal this error is showing in the terminal. The server is running and the webpage is working fine but when I quit the server or run any

whenever I run the server or executing any commands in the terminal this error is showing in the terminal. The server is running and the webpage is working fine but when I quit the server or run any commands(like python manage.py migrate) this error is showing.

   `Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    September 21, 2020 - 12:42:24
    Django version 3.0, using settings 'djangoblog.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CTRL-BREAK.

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:Python37libsite-packagesdjangocoremanagement__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:Python37libsite-packagesdjangocoremanagement__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:Python37libsite-packagesdjangocoremanagementbase.py", line 341, in run_from_argv
    connections.close_all()
  File "C:Python37libsite-packagesdjangodbutils.py", line 230, in close_all
    connection.close()
  File "C:Python37libsite-packagesdjangoutilsasyncio.py", line 24, in inner
    return func(*args, **kwargs)
  File "C:Python37libsite-packagesdjangodbbackendssqlite3base.py", line 261, in close
    if not self.is_in_memory_db():
  File "C:Python37libsite-packagesdjangodbbackendssqlite3base.py", line 380, in is_in_memory_db
    return self.creation.is_in_memory_db(self.settings_dict['NAME'])
  File "C:Python37libsite-packagesdjangodbbackendssqlite3creation.py", line 12, in is_in_memory_db
    return database_name == ':memory:' or 'mode=memory' in database_name
TypeError: argument of type 'WindowsPath' is not iterable
`

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

Comments

@Sieboldianus

I got the following error when running pytest:

>           needquote = (" " in arg) or ("t" in arg) or not arg
E           TypeError: 'WindowsPath' object is not iterable
TypeError: argument of type 'WindowsPath' is not iterable
...Miniconda3envsmanubot-devlibsubprocess.py:461: TypeError

I fixed this by converting path to str:
Line 461: needquote = (" " in str(arg)) or ("t" in str(arg)) or not str(arg)
Line 465: for c in str(arg):

.. according to this suggestion.

My programming background is pretty limited and I am not sure whether this solution fits for all, thus I am sharing it here (and not directly committing).

@dhimmel

@agitter

Thanks for reporting this @Sieboldianus.

If we want to support Windows or test the feasibility of Windows support, we could consider adding AppVeyor for continuous integration testing. I haven’t checked recently whether Travis supports Windows, but not too long ago I saw recommendations for Travis + AppVeyor for testing multiple platforms.

@Sieboldianus

@dhimmel: Many thanks, please feel free to just PR this!

@agitter: I think getting Manubot to run on Windows is not a big deal. I got stuck with another bug towards the end, when running sh build/build.sh with the example Manubot-Rootstock, where I got a compilation error for generating the shortlink to images folder in ...output. I investigated it shortly and think it has something to do with how shortlinks are handled in Windows compared to POSIX systems, but I did not have more time.

dhimmel

added a commit
to dhimmel/manubot
that referenced
this issue

May 30, 2018

@dhimmel

Closes manubot#34
Thanks Alexander Dunkel for reporting the issue.

@dhimmel

#35 now tests this repository on windows, so the manubot CLI should be windows compatible.

@Sieboldianus setting up the travis infrastructure of manubot-rootstock currently doesn’t work on Windows due to an upstream issue. Looks like you’re hitting another issue, perhaps related to the symbolic links. Anyways, if you elaborate about your desired use case, perhaps we can support it or find an acceptable workaround.

dhimmel

added a commit
to dhimmel/manubot
that referenced
this issue

Feb 19, 2020

@dhimmel

Содержание

  1. TypeError: argument of type ‘WindowsPath’ is not iterable #34
  2. Comments
  3. Sieboldianus commented May 29, 2018 •
  4. dhimmel commented May 29, 2018
  5. agitter commented May 29, 2018
  6. Sieboldianus commented May 30, 2018
  7. dhimmel commented Jun 3, 2018

TypeError: argument of type ‘WindowsPath’ is not iterable #34

I got the following error when running pytest :

I fixed this by converting path to str:
Line 461: needquote = (» » in str(arg)) or («t» in str(arg)) or not str(arg)
Line 465: for c in str(arg):

My programming background is pretty limited and I am not sure whether this solution fits for all, thus I am sharing it here (and not directly committing).

The text was updated successfully, but these errors were encountered:

Refs https://bugs.python.org/issue33617. wow, a pretty annoying bug for core python. Looks like there’s a PR open to fix it, but that won’t be available until at least 3.8. So let’s fix this before then.

I’d suggest wrapping the following pathlib.Path objects in str :

@Sieboldianus do you want to make a PR to do that?

I’m not sure whether there will be other issues with running the manubot package on windows. I don’t think we’ve decided whether this package officially supports windows, but if it’s just a few small fixes like this, we might as well for the time being.

Thanks for reporting this @Sieboldianus.

If we want to support Windows or test the feasibility of Windows support, we could consider adding AppVeyor for continuous integration testing. I haven’t checked recently whether Travis supports Windows, but not too long ago I saw recommendations for Travis + AppVeyor for testing multiple platforms.

@dhimmel: Many thanks, please feel free to just PR this!

#35 now tests this repository on windows, so the manubot CLI should be windows compatible.

@Sieboldianus setting up the travis infrastructure of manubot-rootstock currently doesn’t work on Windows due to an upstream issue. Looks like you’re hitting another issue, perhaps related to the symbolic links. Anyways, if you elaborate about your desired use case, perhaps we can support it or find an acceptable workaround.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

Код, который я пытался запустить:

import numpy as np
import os
import cv2
import matplotlib.pyplot as plt
from os import listdir

from pathlib import Path

all_images = list(Path(r'D:/face/train').glob('**/*.jpg'))
np.array([np.array(cv2.imread(str(file))).flatten() for file in all_images])
Path = r'D:facetrain'
print(all_images[0])

Вывод: D: face train F0002 MID1 P00009_face3.jpg

train_images = ([x for x in all_images if val_families not in x])
val_images = ([x for x in all_images if val_families in x])

Я получаю следующую ошибку.

TypeError                                 Traceback (most recent call last)
<ipython-input-8-8de97a2e12c1> in <module>
----> 1 train_images = ([x for x in all_images if val_families not in x])
  2 val_images = ([x for x in all_images if val_families in x])

<ipython-input-8-8de97a2e12c1> in <listcomp>(.0)
----> 1 train_images = ([x for x in all_images if val_families not in x])
  2 val_images = ([x for x in all_images if val_families in x])

TypeError: argument of type 'WindowsPath' is not iterable

Прежде всего, я не использовал класс Path, вместо этого я использовал следующую команду

 all_images = glob(train_folders_path + "*/*/*.jpg")
 print(all_images[0])

Но здесь я получал ошибку индекса. позже я импортировал Path и попробовал первый код, который дал мне желаемый результат. но я получаю ошибку, как я уже упоминал в следующей строке. Пожалуйста, помогите мне решить эту проблему.

1 ответ

Лучший ответ

здесь я получал ошибку индекса.

glob возвращает генератор, а не контейнер. Вы можете перебирать результаты glob, но вы можете сделать это только один раз, и вы не можете использовать индекс для получения первоначального результата.

Если вы хотите использовать результаты несколько раз, или выберите первый с помощью [0], затем используйте list( ... ), как показал ваш первый пример кода. Это будет перебирать результаты и сохранять их в list контейнер, который вы можете повторно использовать или индексировать по своему усмотрению.

В качестве альтернативы вы можете использовать next( ... ) для доступа только к исходный результат, но, похоже, это не то, что вы хотите здесь.

РЕДАКТИРОВАТЬ

что означает, что этот путь WindowsPath не повторяется?

list, полученный из glob, имеет несколько элементов, и каждый из этих элементов — Путь. Вы не можете перебирать Path, точно так же, как вы не можете перебирать int. Вы, конечно, можете перебирать list из Path сек, или более list из int сек.

Вы можете превратить Path в str и перебрать его, как в примере ниже, но это не то, что вам нужно. Обычно вам нужно open(path, 'r') и повторить поверх того , который выводит строки из текстового файла, по одной строке за раз.

>>> from pathlib import Path
>>> 
>>> path = Path('foo')
>>> path
PosixPath('foo')
>>>
>>> for x in path:
...   print(x)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'PosixPath' object is not iterable
>>> 
>>> for x in str(path):
...   print(x)
... 
f
o
o
>>> 


1

J_H
26 Окт 2019 в 18:58

Created on 2020-08-27 14:25 by rasjani, last changed 2022-04-11 14:59 by admin.

Messages (5)
msg375993 — (view) Author: Jani Mikkonen (rasjani) Date: 2020-08-27 14:25
Following code:

```
from pathlib import Path
import os
import subprocess

dir_name = os.environ.get("WORKSPACE", None) or "."
output_directory = Path(dir_name) / "results"
res = subprocess.run(["mytest", "--output", output_directory])
```

Works on macos and linux but on windows, this causes "TypeError: argument of type 'WindowsPath' is not iterable" at https://github.com/python/cpython/blob/master/Lib/subprocess.py#L568

(line is different, depending on the actual python release but i guess that gives the idea where it is)..

Quick test to check if i can do  `" " in Path("/tmp")` on posix platforms shows the same exception but with PosixPath type but apparently this sort of check does not happen on those platforms as the example code works fine there.

It would be nice to be able to pass path objects to subprocess api calls also in windows without explicitly casting the object into string before passing it as argument.
msg375995 — (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-08-27 14:40
See also https://bugs.python.org/issue31961
msg376024 — (view) Author: Jani Mikkonen (rasjani) Date: 2020-08-28 08:59
@xtreak

I went thru the comments of the report you linked. It definitely looks like the discussion was related  but it didnt really fix the issue here.

https://bugs.python.org/issue31961#msg311775 without trying out, that comment actually touches the underlying issue, on windows, list2cmdline throws that typeerror because iterated argument list (output_directory in my example) is WindowsPath and thus not iterable and and testing the arg with "in" operator fails ..
msg376043 — (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-08-28 16:10
I do not understand how you get this result. At that line of code arg can only be string, because it is a result of os.fsdecode(). Are you sure that you use Python version which includes issue31961 changes? What exactly Python version do you use?
msg376760 — (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-09-12 01:28
I closed #41753 as a duplicate of this.  

On that issue, Eryk Sun said "The underlying subprocess.Popen class was updated in 3.8 to support path-like objects in `args` (with shell=False) and `executable` on Windows [1]. This change was not backported to 3.6 and 3.7."

The latter is because 3.6 and 3.7 only get security patches.  Jani, please verify that this is still an issue with 3.8 and/or 3.9.
History
Date User Action Args
2022-04-11 14:59:35 admin set github: 85815
2020-09-12 01:28:59 terry.reedy set nosy:
+ terry.reedy

messages:
+ msg376760
versions:
— Python 3.5, Python 3.6, Python 3.7

2020-09-12 01:25:10 terry.reedy link issue41753 superseder
2020-08-28 16:10:55 serhiy.storchaka set messages:
+ msg376043
2020-08-28 08:59:48 rasjani set messages:
+ msg376024
2020-08-27 14:40:41 xtreak set nosy:
+ serhiy.storchaka, xtreak
messages:
+ msg375995
2020-08-27 14:25:18 rasjani create

(env) C:UsersAmitesh SethiOneDriveDesktopTdjsocial>python manage.py migrate
Traceback (последний последний вызов):
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjsocialmanage.py», строка 22, in
main()
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjsocialmanage.py», строка 18, in main
execute_from_command_line(sys.argv)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagement_init_.py», строка 419, in execute_from_command_line
utility.execute()
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagement_init_.py», строка 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagementbase.py», строка
354, in run_from_argv
self.execute(*args, **cmd_options)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagementbase.py», строка
398, in execute
output = self.handle(*args, **options)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagementbase.py», строка
89, в wrapped
res = handle_func(*args, **kwargs)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagementcommandsmigrate.py», строка 75, в handle
self.check(databases=[database])
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocoremanagementbase.py», строка
419, в check
all_issues = checks.run_checks(
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocorechecksregistry.py», строка
76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocontribstaticfileschecks.py», строка 7, в check_finders
for finder in get_finders():
File «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocontribstaticfilesfinders.py», line 281, in get_finders
yield get_finder(finder_path)
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocontribstaticfilesfinders.py», строка 294, in get_finder
return Finder()
Файл «C:UsersAmitesh SethiOneDriveDesktopTdjenvlibsite-packagesdjangocontribstaticfilesfinders.py», строка 57, in init
for root in settings.STATICFILES_DIRS:
TypeError: объект ‘WindowsPath’ не является итерируемым

Вернуться на верх

Mar 24, 2016 TypeError: argument of type ‘WindowsPath’ is not iterable How can I solve this problem and the pdf files to be opened according the input file? And another issue: how can I …
From stackoverflow.com
Reviews 1
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE …

Sep 20, 2020 1 Answer Sorted by: 42 I got this cleared by changing DATABASES in settings.py file: change ‘NAME’: BASE_DIR / ‘db.sqlite3’, to ‘NAME’: str (os.path.join …
From stackoverflow.com
Reviews 5
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE CODE …

Jun 3, 2021 TypeError: Register () missing 1 required positional argument: ‘request’. TypeError: ‘NoneType’ object is not iterable. resource wordnet not found python. …
From codegrepper.com
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE

2023-01-241- TypeError: ‘NoneType’ object is not subscriptable &2-TypeError: argument of type ‘WindowsPath’ is not iterable solved in Django’NAME’: BASE_DIR / ‘db.sqli…
From youtube.com
See details »


TYPEERROR: ‘PATHCOLLECTION’ OBJECT IS NOT ITERABLE WHEN ADDING …

2023-01-24TypeError: ‘PathCollection’ object is not iterable when adding second legend to plot. Ask Question Asked 6 years, 3 months ago. Modified 5 years, 10 months ago. Viewed 19k times …
From stackoverflow.com
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE #6894

Aug 28, 2020 os.path.join() there is no mention in the documentation about to use os.path.join() just only for media root but there is no mention to use it in the database and I …
From github.com
See details »


TYPEERROR: ‘X’ IS NOT ITERABLE — JAVASCRIPT | MDN — MOZILLA

Dec 13, 2022 TypeError: ‘x’ is not iterable The JavaScript exception «is not iterable» occurs when the value which is given as the right-hand side of for…of , as argument of a function such …
From developer.mozilla.org
See details »


DJANGO : TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT …

2023-01-24Django : TypeError: argument of type ‘WindowsPath’ is not iterable — in django python [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] …
From youtube.com
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE #4

Nov 14, 2021 needquote = (» » in arg) or («t» in arg) or not arg TypeError: argument of type ‘WindowsPath’ is not iterable. The text was updated successfully, but these errors were …
From github.com
See details »


‘WINDOWSPATH’ OBJECT IS NOT ITERABLE · ISSUE #1327 — GITHUB

Dec 12, 2018 ‘WindowsPath’ object is not iterable #1327 Closed find-happiness opened this issue on · 1 comment find-happiness commented on sgugger …
From github.com
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE #34

May 29, 2018 TypeError: argument of type ‘WindowsPath’ is not iterable · Issue #34 · manubot/manubot · GitHub manubot / manubot Public Notifications Fork 38 Star 358 Code …
From github.com
See details »


TYPEERROR: ARGUMENT OF TYPE ‘WINDOWSPATH’ IS NOT ITERABLE #1

Jan 2, 2021 TypeError: argument of type ‘WindowsPath’ is not iterable #1. Closed Pomax opened this issue Jan 3, 2021 · 9 comments … or («t» in arg) or not arg TypeError: argument …
From github.com
See details »


ORTHO4XP ERROR: TYPEERROR: ‘MULTIPOLYGON’ OBJECT IS NOT ITERABLE

2023-01-24When I click Batch Build it initially starts, but then stops responding right away with the following error: TypeError: ‘MultiPolygon’ object is not iterable This is on a Apple Mac Studio with …
From reddit.com
See details »


WHY DO I GET THE TYPEERROR «ARGUMENT OF TYPE ‘TYPE’ IS …

Dec 18, 2016 1 Answer. That creates a reference to the type object dict, not an empty dictionary. That type object is indeed not iterable: >>> ‘foo’ in dict Traceback (most recent …
From stackoverflow.com
See details »


ERROR: ARGUMENT OF TYPE WINDOWSPATH IS NOT ITERABLE

Mar 28, 2022 A pathlib.Path or just Path, for short, is essentially a Python representation of a file path. Its typically more convenient than working with the path as a plain string, since you can …
From discuss.python.org
See details »


Related Search


Like this post? Please share to your friends:
  • Windows movie maker для виндовс 7 скачать бесплатно
  • Windows movie maker для вин 7
  • Windows movie maker для windows как пользоваться
  • Windows movie maker для windows xp sp3
  • Windows movie maker для windows xp 32 bit скачать торрент