Skip to content
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

Simple print command not working #3272

Closed
chrmarti opened this issue Nov 9, 2018 · 11 comments
Closed

Simple print command not working #3272

chrmarti opened this issue Nov 9, 2018 · 11 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@chrmarti
Copy link

chrmarti commented Nov 9, 2018

From @roberti on November 8, 2018 9:43

Issue Type: Bug

the code in file foo.py is:

# simple print
print('hell')

The result is:
Exception has occurred: AttributeError
'NoneType' object has no attribute 'write'
File "C:\Projetos\Faculdade\POO\python\datas.py", line 4, in
print('hell')

It is working perfectly in python console. Does not work in Visual Studio Code.

VS Code version: Code 1.28.2 (7f3ce96ff4729c91352ae6def877e59c561f4850, 2018-10-17T00:23:51.859Z)
OS version: Windows_NT x64 10.0.17134

System Info
Item Value
CPUs Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz (8 x 1800)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
Memory (System) 7.86GB (2.44GB free)
Process Argv
Screen Reader no
VM 0%
Extensions (2)
Extension Author (truncated) Version
anaconda-extension-pack ms- 1.0.1
python ms- 2018.9.2

Copied from original issue: microsoft/vscode#62771

@chrmarti
Copy link
Author

chrmarti commented Nov 9, 2018

From @vscodebot[bot] on November 8, 2018 9:43

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@chrmarti
Copy link
Author

chrmarti commented Nov 9, 2018

How do you run the file from VS Code? What is the Python console you mention?

@chrmarti
Copy link
Author

chrmarti commented Nov 9, 2018

From @roberti on November 8, 2018 15:32

It is really that simple as it sounds. But, lets go...

How do you run the file from VS Code? (F5, configured to run in integrated terminal)
What is the Python console you mention? (VS Code console, type python and voila. From command prompt type python and voila!)

@chrmarti
Copy link
Author

chrmarti commented Nov 9, 2018

From @roberti on November 8, 2018 15:34

Even other simple samples are not running on VS Code like this one.

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Welcome to machine learning model APIs!"

if __name__ == '__main__':
    app.run()

The error:
xception has occurred: AttributeError
'NoneType' object has no attribute 'isatty'
File "C:\Projetos\Faculdade\POO\python\foo.py", line 9, in
app.run()

@roberti
Copy link

roberti commented Nov 9, 2018

Any idea what to try?
Already tryed all alternatives in my pocket.
Installed other IDEs for continue working with my students in the classroom (Jupyter, Spyder and PyCharm), all of them working ok.
The problem seems to be something in VS Code debugger, or in the interface between VS Code and python interpreter. It is not only related to print command, it occurs with many othe situations were you have objects been instatiated.

@Ronkiro
Copy link

Ronkiro commented Nov 9, 2018

Mind sharing your settings.json?
You can open it by CTRL + SHIFT + P -> Preferences: Open Settings (JSON)

Also, did you config any environments on VSCode? How is it configured?
When you tried running via other IDEs, did you use the same envs to debug, and it worked??

Could you try typeof('hell') to see if it recognizes as NoneType?

When you changed the run code key, did you also change the debug keys that use F5? (Continue/Start)

EDIT:
Sorry, for future help on troubleshooting reference, the correct method is "type". I mistyped typeof

@roberti
Copy link

roberti commented Nov 9, 2018

json file attached.
settings.json.txt

no envs configured (new laptop installation, no work done here still now). just intalled some IDEs and run dummy samples to check the installation (standard procedure).

used same package and files to test in all different tools

typeof does not exist... but type('hell') works (actually it does not produce any output in a .py file inside vs code, but the line is executed with no exception raised).

no keys changed.

@DonJayamanne
Copy link

What's the path to the python executable?
You could either get it from python.pythonPath from settings.json or the tooltip on the interpreter information displayed at the bottom left of the VS Code statusbar.

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster feature-interpreter labels Nov 9, 2018
@DonJayamanne DonJayamanne self-assigned this Nov 9, 2018
@roberti
Copy link

roberti commented Nov 9, 2018

Same path as other IDEs...
C:\ProgramData\Anaconda3\

But... as you mentioned it now I made some new tests...
I don't know why, but the default executable set is "pythonw.exe" (I really didn't realized that w there untill now, I'm sorry).
Changing to "python.exe" the things work. With "pythonw.exe" the problem occurs. Actually I googled it and found the difference, and seems that the error is actually the normal behaviour for pythonw.exe.
Just can't imagine why that executable was set as default in the instalation process (I've installed VS Code through the end of Anaconda instalation).
Anyway, thank you for the assistance!
And very sorry for not have seen that before (I really had read all the settings.json relevant attributes - python path included, and didn't see that).

Best regards!

Waldemar

@gonghwa
Copy link

gonghwa commented Nov 19, 2018

After I installed 64bit anaconda recently and vs code from anaconda it works exactly like yours. I think it is a mistake from anaconda.

@roberti
Copy link

roberti commented Nov 20, 2018

I Agree. Probably this behaviour came from the anaconda installer. It is very time consuming - specially for people that uses python occasionaly. Is there a way to report it to anaconda?

@lock lock bot locked as resolved and limited conversation to collaborators Dec 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants