First time here? Check out the FAQ!
1

venv3.7 and typing

How to use typing in debugging?

Attempting to use * from typing import Generator * or * from typing import Dict * in the code results in an error.

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
Traceback (most recent call last):
  Оболочка Python, prompt 1, строка 1
    # Used internally for debug sandbox under external interpreter
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1357, из <module>    class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
  Файл "c:\VENV37\Lib\site-packages\typing.py", строка 1005, из __new__    self._abc_registry = extra._abc_registry
builtins.AttributeError: type object 'Callable' has no attribute '_abc_registry'

When you call the same code in the console, everything is fine.

(VENV37) AC..........OKS\ClassTasksPython
$ python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Generator
>>> def fib6(n: int) -> Generator[int, None, None]:
...     yield 0
...     if n > 0:
...         yield 1
...     last: int = 0
...     next: int = 1
...     for _ in range(1, n):
...         last, next = next, last + next
...         yield next
...
>>>
>>> if __name__ == '__main__':
...     for i in fib6(50):
...         print(i)
...
0
1
1
2
3
5
8
13
21
Alexander_Dragunkin's avatar
38
Alexander_Dragunkin
asked 2020-05-04 10:11:17 -0500
Wingware Support's avatar
4k
Wingware Support
updated 2020-05-06 10:19:18 -0500
edit flag offensive 0 remove flag close merge delete

Comments

I can't seem to reproduce this. What is your sys.path? It's odd that typing is being imported from c:\VENV37\Lib\site-packages\ rather than the stdlib of the base interpreter. What is the current directory in both cases?

Wingware Support's avatar Wingware Support (2020-05-04 17:20:31 -0500) edit

import sys sys.path ['', 'c:\VENV37', 'c:\VENV37\Lib', 'c:\VENV37\Lib\site-packages', 'c:\BOOKS\ClassTasksPython', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32', 'C:\Users\ACER\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\lib\site-packages', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32\lib', 'C:\Users\ACER\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Pythonwin']

current directory c:\BOOKS\ClassTasksPython

Alexander_Dragunkin's avatar Alexander_Dragunkin (2020-05-17 04:16:45 -0500) edit

I seem to understand what my mistake is.

I removed from sys.path 'c:\VENV37', 'c:\VENV37\Lib', 'c:\VENV37\Lib\site-packages' and it worked

Alexander_Dragunkin's avatar Alexander_Dragunkin (2020-05-17 06:58:35 -0500) edit
add a comment see more comments

1 Answer

1

Perhaps my comments can help someone.

To configure debugging in a virtual environment, in the project properties tab environment, specify the path to the activate file. In the phython path section, select Use Default or do not write (in the case of customs) the path to the folders of the virtual environment

Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['',
 'c:\\Users\\ACER\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
 'c:\\Users\\ACER\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
 'c:\\Users\\ACER\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
 'c:\\Users\\ACER\\AppData\\Local\\Programs\\Python\\Python37-32',
 'c:\\VENV37',
 'c:\\VENV37\\lib\\site-packages']
Alexander_Dragunkin's avatar
38
Alexander_Dragunkin
answered 2020-05-17 08:04:10 -0500, updated 2020-05-17 08:06:28 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer