microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.29k stars 1.17k forks source link

Problem with having a "types.py" file in working folder on W10 #4779

Closed rowem closed 5 years ago

rowem commented 5 years ago

Issue Type: Bug

I am using a W10 PC to create Python scripts on VSC and got the error message below, which is being generated by the line "player_count = heights.count(185)", where "heights" is a python list.

" from types import MappingProxyType, DynamicClassAttribute ImportError: cannot import name 'MappingProxyType' from 'types' (C:\Users\OneDrive\datacamp\intro_to_python\types.py)"

The problem is caused by having another python script called "types.py" in the same working folder. If I change the name of this script to "datatypes.py" then the error goes away.

I tried this on a Linux PC with VSC and couldn't replicate the problem, so it seems to be just W10, where I can replicate this problem.

I am just a uni student so no expert on this but it appears that VSC on W10 is looking for a system "types.py" file in my python installation but is instead reading the "types.py" file in my working folder, where it cannot find the required function. If I run "print(sys.path)", then I can see my python working folder (same on Linux PC), which is what I would have expected. Not sure if this a bug, or if there are reserved python filenames that you should't use, but then VSC on Linux would produce the same problem.............so I have uploaded this as my first VSC issue.

Environment data

4721

Expected behaviour

I should be able to have a file called "types.py" in my working folder without it causing error messages when I use python functions like "count".

Actual behaviour

" from types import MappingProxyType, DynamicClassAttribute ImportError: cannot import name 'MappingProxyType' from 'types' (C:\Users\OneDrive\datacamp\intro_to_python\types.py)"

Steps to reproduce:

The problem is caused by having another python script called "types.py" in the same working folder. If I change the name of this script to "datatypes.py" then the error goes away.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

DonJayamanne commented 5 years ago

Please rename the file from types.py to my_types.py or other. The module conflicts with the types module in the standard lib.