I am running python 3.3.5. I can't figure out how to launch the IDLE IDE. I installed everything correctly but the IDLE doesn't appear anywhere.
To start it from the command line in Python 3.3+:
$ python3 -midlelib
Or in the code:
import idlelib.PyShell
idlelib.PyShell.main()
You will find an idle.py file at C:\Python33\Lib\idlelib.
There are 2 idle.pys file and both of them work. The first opens a command prompt alongside idle and the other doesn't.
Related
I want to convert the following sample python program into an executable file:
import os
print(os.getcwd())
To convert it into an executable I have used Pyinstaller:
pyinstaller app.py --onefile
And the EXE file is getting generated in the dist folder, but when I run it, it launches and immediately closes, and the expected print statement is not even displayed.
What could be the issue?
It does prints the statement, but just after printing it the code ends. You can add input() or use time.sleep(seconds) to make your program wait until you press a key or any particular number of seconds respectivly.
To check if your code(without the advice i have given) prints, start that python file in your command line.
I have tried nearly all solutions in my mind to do this, but the fact is I can't run a python script with modules imported already.
Here's my code for the module cls.py:
import os
def cls():
os.system('cls')
Given below is the code for opening python in cmd:
#echo off
python
pause
What I need is to open the python in the command prompt with the module cls imported. Also, when I try python -m <module> way, it doesn't show any errors, but the program ends.
Any help would be greatly appreciated and thanks in advance.
Saw this question related to mine, but it is not my problem: Run python script that imports modules with batch file
I think what you'r looking for is the interactive mode:
-i
When a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command
So just use python -i cls.py in your batch file. This would import your Python file and stay in the Python interpreter prompt. You could then just call cls() because it's already imported.
Alternatively, you could set the environment variable PYTHONSTARTUP in your batch file:
If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode. The file is executed in the same namespace where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session.
Background:
I recently installed curses with pip install curses
I found a couple tutorials online (https://www.devdungeon.com/content/curses-programming-python, https://docs.python.org/3/howto/curses.html, https://www.youtube.com/watch?v=rbasThWVb-c)
I always constantly testrun my code when I install a new package or learn something new
Whenever I run s = curses.initscr() in IDLE, I get this error message:
File "C:/Users/jacob/AppData/Local/Programs/Python/Python37-32/screentest.py", line 3, in <module>
s = curses.initscr()
File "C:\Users\jacob\AppData\Local\Programs\Python\Python37-32\lib\curses\__init__.py", line 30, in initscr
fd=_sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'
This is the message from PyCharm:
Redirection is not supported.
Process finished with exit code 1
And when I run a sample snippet from DevDungeon,
print("Preparing to initialize screen...")
screen = curses.initscr()
print("Screen initialized.")
screen.refresh()
curses.napms(2000)
curses.endwin()
print("Window ended.")
in command prompt with python booted, it just gives an uninteractable blank screen.
Is the thing happening in shell correct?
What the hell is going on?
How can I fix this?
please help thank you
sys.__stdout__ is the original sys.stdout for a python process. When you start python with pythonw.exe, which only exists on Windows, python initially executes stdout = __stdout__ = None. (I am not sure about what happens on *nix.) pythonw.exe is used to run python with a GUI UI without an associated text console. On Windows, the IDLE icons and Start menu entries run python with pythonw. Same with other GUI IDEs.
curses runs with text terminals or consoles. It assumes that sys.__stdout__ is such. It cannot work when sys.__stdout__ is None.
If you start IDLE from a command line terminal/console with python -m idlelib, sys.__stdout__ will be that terminal, and it will have a fileno(). What will happen after that I do not know. If your program uses curses, you are likely better off to run it in the text console.
I am running into a problem with mysql.connector in Python 3.7 on Windows. I don't know if it's a conflict with the Python 2.7 installation that I did a few days ago. The original script was working fine last time I checked (more than a month ago). The system variables seem fine. Python 3.7 is there.
I isolated the issue to demonstrate better what is going on.
When I attempt to import mysql.connector with IDLE it raises no issues.
IDLE import mysql.connector
Now, with a simple script
import mysql.connector
print("Hello!")
input("Exit.")
again it's fine if I run it with IDLE editor:
Run script with IDLE editor
In fact, the original script runs as intended with IDLE editor.
But, when I attempt to run the script from cmd with 'python test.py' I get this error:
CMD execute script
Of course, when I try to open the script by double-clicking on it, the window opens and closes immediately. I'd appreciate your help on this issue.
First check your python version using python -V if its not 3.7, then use below to execute code from cmd.
python3 test.py
I'm a beginner of Python and I want to run a python3 script in PyCharm Python Console, but it raise an error below:
>>> /Users/mymac/Documents/Python/test.py
File "<input>", line1
/Users/mymac/Documents/Python/test.py
^
SyntaxError: invalid syntax
I don't know what's wrong the file path is, how can I solve the problem?
use execfile('/Users/mymac/Documents/Python/test.py'). You are trying to run a python file like an executable. On top of that you are doing it in python interpreter.
Use python's execfile routine to call a file from interpreter or use python test.py to run it from the terminal.
I recognized that the answer I accepted ahead wasn't a perfect method, cause function execfile has been deleted in Python3, the alternative method is using open like:
>>> with open ('/Users/mymac/Documents/Python/test.py', 'r') as f:
... exec(f.read())
...
Still thanks for guys who helped me!
This could be several things. Have you set your environmental correctly? You can test this by cmd: python it should return Python 3.6.4 if that is your current version. If not then head over to tutorialsPoint for how to correctly set up your path.
If that is correctly configured, then have you selected an interpreter in PyCharm. If not, File --> Settings --> Project: Network --> Project Interpreter. Select your python installation path.
Another thing to note is that I suspect you mean to use the terminal instead of the python console.
Then in PyCharms terminal section, python test.py.