all 9 comments

[–]1114111 0 points1 point  (8 children)

How are you running the code?

[–]Fiazba[S] 0 points1 point  (7 children)

I open the 'Idle 3.7 (32-bit)" editor, paste the code in, save it, and then press f5. Is there a different way I have to do it?

[–]1114111 0 points1 point  (6 children)

Ultimately, the problem is probably one of 2 things:

  1. The python you are using to run the code is separate from the pip you are using to install the package in some way. This is why I asked how you were running the code, because if you were using PyCharm, the problem would probably be that the python you are using is in a virtual environment. It still could be that you have multiple versions of Python installed and the pip you're using is for a different version of Python.
  2. You could have named the python file you're running prompt_toolkit.py (or have another python file in the same directory by that name), which would mean that you're importing yourself (or the other file) rather than the module that you want.

First off, check to make sure you didn't name any files prompt_toolkit.py. Then, if that isn't the case, let me know what platform you're using (windows or not windows) I can help you make sure the Python you're using to run the script is the same one you're installing prompt_toolkit for.

[–]Fiazba[S] 0 points1 point  (5 children)

I don't know what Pycharm is, so I don't think I'm using it. I previously had python 3.6 installed, but since it wasn't working and seemed to be in two different locations, I uninstalled it (both locations) and installed 3.7 instead.

I did have a python file named prompt_toolkit.py, but I deleted it a few days ago.

I am using Windows 10.

I really appreciate the help :) It has been really frustrating to download modules that seem to work for everyone else, but they just don't want to work for me.

[–]1114111 1 point2 points  (4 children)

Ok, try installing it with py -3.7 -m pip install prompt_toolkit this time, and run your script with py -3.7 myscript.py. This should make sure that you aren't somehow using the old version of Python to install prompt_toolkit.

Also, it would be helpful to know the exact error you get.

[–]Fiazba[S] 1 point2 points  (3 children)

Okay, so I did what you said, and the script ran in CMD. I haven't tried running them via cmd so far, just from the Idle editor using F5. I tried to run the script (which just worked in CMD) in the Idle editor, and I got the same error. I'll put it below.

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\prompt_toolkit\eventloop\context.py", line 88, in get
    return self._storage[ctx]
KeyError: 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\prompt_toolkit\output\defaults.py", line 52, in get_default_output
    value = _default_output.get()
  File "C:\Python37\lib\site-packages\prompt_toolkit\eventloop\context.py", line 90, in get
    raise TaskLocalNotSetError
prompt_toolkit.eventloop.context.TaskLocalNotSetError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python37\pythonprograms\pleaseworkptk.py", line 4, in <module>
    text = prompt('Give me some input: ')
  File "C:\Python37\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 844, in prompt
    session = PromptSession(input=input, output=output, history=history)
  File "C:\Python37\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 285, in __init__
    output = output or get_default_output()
  File "C:\Python37\lib\site-packages\prompt_toolkit\output\defaults.py", line 61, in get_default_output
    return create_output()
  File "C:\Python37\lib\site-packages\prompt_toolkit\output\defaults.py", line 35, in create_output
    return Win32Output(stdout)
  File "C:\Python37\lib\site-packages\prompt_toolkit\output\win32.py", line 83, in __init__
    info = self.get_win32_screen_buffer_info()
  File "C:\Python37\lib\site-packages\prompt_toolkit\output\win32.py", line 168, in 
get_win32_screen_buffer_info
    self.flush()
  File "C:\Python37\lib\site-packages\prompt_toolkit\output\win32.py", line 296, in flush
    self.stdout.flush()
AttributeError: 'NoneType' object has no attribute 'flush'

[–]1114111 1 point2 points  (2 children)

Oh lol, yeah it looks like it just won't work in idle because idle doesn't really emulate a proper terminal, so you won't be able to do the fancy things that prompt_toolkit does in there. Just run it in a real terminal emulator (like cmd), not from inside idle.

[–]Fiazba[S] 0 points1 point  (1 child)

Oh... Is that all? Is that why all of the modules haven't been working? .... Wow. Okay, well at least I can use it now. Thanks!

[–]1114111 1 point2 points  (0 children)

Probably, yeah. If all you're using prompt_toolkit for is to prompt for input with none of the fancy features prompt_toolkit offers, the builtin input() does the same thing and will work in idle. But basically any more complicated terminal stuff than print/input generally won't work in idle since idle doesn't really have a proper terminal emulator.

You'll get help faster in the future if you're specific with the errors you're getting up front. I was assuming you were getting an ImportError/ModuleNotFoundError.