Curses crash on execute (Python 3.7.2 on Windows 10) - python

Found out about Curses a couple days ago and wanted to start messing around with it to see what I could create.
I followed some instructions for installation on another thread and it installed just fine. However, when I attempt to run initscr() (which initializes the screen, it crashes)
Here's the Error text:
{Traceback (most recent call last):
File "C:\Users\ADimi\Desktop\Wing Workspace\test.py", line 2, in <module>
stdscr = curses.initscr()
File "C:\Users\ADimi\AppData\Local\Programs\Python\Python37\lib\curses\__init__.py", line 30, in initscr
fd=_sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'}
To recreate:
You can run this in either, idle or a seperate file. For me this directly causes the error, specficially line 2. stdscr = curses.initscr()
import curses
stdscr = curses.initscr()
From what I'm understanding from the error itself, _sys.__stdout__ is returning a NoneType and thus leading to a crash.
I tried to find similar issues online and have had no luck. Any help at this point could help out a lot I'd love to get this working.
Here's a link about curses:
https://docs.python.org/2/howto/curses.html#curses-howto
Here's where I found out about curses, the first comment is the installation instructions I followed:
What is needed for curses in Python 3.4 on Windows7?
Thanks in advance.
EDIT:
I have some what found a fix. There is a windows tailored version of curses found here: https://pypi.org/project/windows-curses/#files
After uninstalling the old curses and installing this you must follow some intermediate steps:
Create a file with this test code:
import curses
import time
screen = curses.initscr()
screen.clear()
time.sleep(4)
Create a path for 'python' for your cmd prompt:
https://www.pythoncentral.io/add-python-to-path-python-is-not-recognized-as-an-internal-or-external-command/
Now using the cmd prompt open the file:
python test.py
You should be presented with a black screen for 4 seconds, then it will close.
This is the only work around I've come across, I will keep searching and updating as I go thank you.

Related

Vs code doesn't regognize tkinter on pop os

I have a code, where i use tkinter to make a window and stuff. It's a brawler picker for brawl stars. Im using pop os-linux and vs code and i have tried so many ways, but anything doesn't work.
When i run the code, i get this:
(.venv) sh-5.1$ python -u "/home/"my_name"/Documents/Vs-code_projektit/Joku.py"
Traceback (most recent call last):
File "/home/"my_name"/Documents/Vs-code_projektit/Joku.py", line 2, in <module>
from tkinter import *
ModuleNotFoundError: No module named 'tkinter'
And in the vs code itself, it regognizes the tkinter and turns the text green, but after that nothing relating to tkinter doesn't work and i shows an error. Btw i have the full code already cause i copied from my dual boot windows and i wanted to try it here,
What should i do to make it work?
EDIT:
For everybody who has the same problem, it may be caused by the app version. I posted this on reddit cause i didn't get answer in time, and someone suggested that i download vs code with appimage, snap, or in my case pop!_os Installation.
MAIN POINT: Someone said that NEVER use FLATPACK with ides. It may work for other apps but never use it with ides. It can't handle system packages or modules.
First of all, you need to know what interpreter is currently used by vscode, which is displayed in the lower right corner of the interface.
Clicking on the displayed python version will open a Select Interpreter panel where you can select the interpreter with the tkinter package installed to run the code
Or you can install the tkinter package for the currently used interpreter.
<path-to-current-python.exe> -m pip install tkinter
EDIT
From your terminal information it can be seen that you have activated the virtual environment, but you are running the code with Code Runner.
As a reminder, Code Runner doesn't change interpreters as you select another interpreter in the Select Interpreter panel. So please use the Run Pythonn File option provided by the official Python extension to run the code.

How do I run Pygame on Pycharm

I am trying to run pygame on the PyCharm IDE, I have installed the latest version of pygame for python 3.5 and have added it to the project interpreter. I installed pygame from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame and copied it too python35-32/Scripts/. The test program below runs fine in the python shell but I want to run it from PyCharm.
I have been trying to solve this for the past hour and I've hit a wall.
When I run this simple test program to see if pygame is working:
import pygame
pygame.init()
pygame.display.set_mode((800, 800))
I get this error:
Traceback (most recent call last):
File "C:/Users/jerem/PycharmProjects/Games/hello_pygame.py", line 1, in <module>
import pygame
File "C:\Users\jerem\AppData\Roaming\Python\Python35\site-packages\pygame\__init__.py", line 141, in <module>
from pygame.base import *
ImportError: No module named 'pygame.base'
Any help would be greatly appreiciated!
Thanks again,
JC
Follow the instructions provided here. I think its related to the problem you are having on pygame and PyCharm on windows.
How do I download Pygame for Python 3.5.1?
its bcus pycharme has not recognised you're env or working on wrong env
https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html
check this

Trying to import mcpi.minecraft on my Mac but I keep getting errors

I have recent acquired the book adventures in Minecraft and want to give it a try on my Mac. I follow the instructions until it tells me to type this code into my python 2.7:
import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()
mc.postToChat("Hello Minecraft World")
I keep receiving a error stating that no module named mcpi.minecraft exists. I checked the folder that stores my program and it does have an mcpi folder. Does anybody have the solution?
I had the same issue. I ended up not even using IDLE. I just write the commands into a separate terminal window form the one I am running the server on.
I have not written any scripts yet and tried to run them in this way but I am sure it works.
If you use the terminal rather than IDLE (like me) I would pip install mcpi
I use
from mcpi.minecraft import Minecraft
mc = Minecraft.create()
I also decided to read this book and faced the same problem. You just need to save the file by the path: / AdventuresInMinecraft / MyAdventures here you save your file.

py2exe doesnt create windows executable(.exe)file ,Console window appears and vanishes soon when i press Exe file

This is what i have tried till now is :
I have created a setup.py file and in this written the following code.
#setup.py
from distutils.core import setup
import py2exe
import time
setup(console=['myprogram.py'])
time.sleep(2)
then in command prompt i entered into working directory and run this command
**python setup.py install**
**python setup.py py2exe**
But when i click on the exe file the console window appears and vanishes soon. Can anyone suggest where i went wrong.
I am using python 2.7.6, IDLE.Advance thanks. I googled with no much help .
Is there anything to do with dll or the python path??? I may have done some changes.
My program consists of openCV code and tkinter code for creating GUI in python.
I thought time.sleep(2) would had been the problem , but its not the issue, i tried checking it.
The console window is your application. I don't know what it should do but it think that it vanishes because of some exception. Add a logging or something so you will be able to see what goes wrong there.

Tkinter for Windows7-64Bit

Can you please let me know how to download tkinter for windows 7 64bit. I am getting an error while i do it:
from Tkinter import *)
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
from Tkinter import *
ImportError: No module named 'Tkinter'
If you are using python 3 then the code would use a lower case tkinter.
#python 2
from Tkinter import *
#python 3
from tkinter import *
if that doesn't fix it then you can install it in several ways. check out this page: http://www.tkdocs.com/tutorial/install.html
If you can't get that to work another option is using pip. pip allows you to install modules easily. If you have the newest version if python 2 then it is installed and all you have to do is set a path. Click the start button and right click on computer. Select properties and then advanced settings. Under one of the tabs is a button called environment variables. Click on it and in the new windows scroll down until you see the word "path" on the right. Click on the text to the left of it and put in a ; to put in a new path. I don't know exactly how your file structure is but find python and set a path to the folder called scripts within python. An example would be something like this: "C:\python27\scripts".
There are two possible reasons that you are not able to get Tkinter working:
First Reason
First, this is dependent on if you have installed tk onto your computer. To find out if you have, and what version, run a Python shell via:
% C:\python32\python
From the Python command prompt, enter these two commands:
>>> import tkinter
>>> tkinter._test()
This should pop up a small window; the first line at the top of the window should say "This is Tcl/Tk version 8.5"; Or whatever version has been installed on your computer. If you haven't installed, you'll want to get tkinter on there. I've found the following that may help with that:
http://www.tkdocs.com/tutorial/install.html
Second Reason
If installing tkinter onto your machine isn't the issue, then this is most likely due to what version of python you are using, as this will change some small things.
Python 3:
from tkinter import *
Python 2.7:
from Tkinter import *
If you have python you are trying to run from 2.7 or before but are using it in Python 3, you may find the 2to3 tool helpful for adapting:
https://docs.python.org/2/glossary.html#term-to3
open IDLE Python GUI and type in import tkinter and after that type import_tkinter and if you wanna run a test just type in tkinter._test()
works for python 3.4.3

Categories