I have a problem through pyautogui I need to know the position of my cursor but when I enter the code and press run in the console nothing happens
enter image description here
I'm just starting to understand python
You aren't running the file. Note how it says "Python Console" in the tab header. That indicates that no file is imported and run by default.
Right-click on the background of the editor, and press "Run file in Python console". You'll notice that it will open a new tab with a header of the file name, and your code will execute.
Related
I am new to coding and would like to know how do I run a program on a terminal thing. I am following a video in which a person types out the name of the file he wants to run and it runs. What terminal/prompt/window do I need to type this in. I have a photo of the video tutorial and a photo of my desktop with all of my terminal applications. I keep getting errors, please help.
Tutorial video showing the commands
my terminal/prompt type applications
Step 1: Create a python file in any directory of your choice
Step 2: edit python file and add some code (whatever you want to run)
Step 3: Open CMD by either clicking on Start and typing "cmd" or pressing and holding the "Start/Windows" button on your keyboard and pressing "R" on your keyboard, this will open a run window on the bottom left that looks like this
In that "run" window type cmd. this will open a window that looks like this
Step 4: After opening CMD you will be able to type in it. type cd (Stands for change directory) and type or paste the directory of where the python file is located and press "Enter" Now you are in the directory of the python file see this for more detailed instructions on changing directories Change Directories
Step 5: Type in the name of the python file, in this case, its "Hello World.py" and press "Enter" this will run the python file in cmd and show the result of the file in cmd
Good luck with your coding venture!
I have a python file named "python_file.py" and I want to run it with a command line such as "python python_file.py" by typing it in the terminal, and not in the python console. I succeed one time, but when I change my working directory, it no longer works.
When I tried, it displays something like "python isn't known as a intern program, a runnable program or a command file".
And I'm using Python 3.7.
Can someone help me ?
You need to create a run/debug configuration, as explained in the official help:
Click on the button left of the green arrow symbol (the green arrow might be greyed out, but that's fine):
Click on Edit Configurations.
Click on the + symbol
Click on Python.
On the right side, enter/activate the following:
Name (a string that describes your according project)
Single instance only (this is less complicated for you)
Click on the Configuration tab.
Select a type of target from the Script path/Module name
Enter the path to your Python script in the according box.
Select the Python interpreter (Python 3.x will be fine).
In the Execution section, select either Emulate terminal in output console or Run with Python console.
Apply the changes and close the dialog.
Click on the button left of the green arrow symbol to run your program from the internal command line.
I've searched on stackoverflow and Googled but don't see the following issue addressed.
Using Python 3.5 on Spyder, when I hit the Run button to execute the script in an ALREADY saved .py file a Save File window pops up twice. All I have to do is hit Cancel twice to run the script, so not a big problem, but it's irksome.
For example, Save File opens when I try to execute:
def summing(s,p):
return s + p
print(summing(1,2))
However, when I highlight the code and right-click on "Run selection or current line" the script simply executes (no Save File window pops up).
How can I stop Save File windows from opening when I hit the Run button?
For some reason Spyder requires that all open files are saved (the tabs on the upper left of the user interface), not just the active script you are running. Once all tabs are properly saved the code will run with no save file prompt.
I have installed Python and written a program in Notepad++.
Now when I try to type the Python file name in the Run window, all that I see is a black window opening for a second and then closing.
I cant run the file at all, how can run this file?
Also I want to tell that I also tried to be in the same directory as a particular Python file but no success.
I assume you are running the script with command python file_name.py.
You can prevent closing of the cmd by getting a character from user.
use raw_input() function to get a character (which probably could be an enter).
It sounds like you are entering your script name directly into the Windows Run prompt (possibly Windows XP?). This will launch Python in a black command prompt window and run your script. As soon as the script finishes, the command prompt window will automatically close.
You have a number of alternatives:
First manually start a command prompt by just typing cmd in the Run window. From here you can change to the directory you want and run your Python script.
Create a Windows shortcut on the desktop. Right click on the desktop and select New > Shortcut. Here you can enter your script name as python -i script.py, and a name for the shortcut. After finishing, right click on your new shortcut on the desktop and select Properties, you can now specify the folder you want to run the script from. When the script completes, the Python shell will remain open until you exit it.
As you are using Notepad++, you could consider installing the Notepad++ NppExec plugin which would let you run your script inside Notepad++. The output would then be displayed in a console output window inside Notepad++.
As mentioned, you can add something to your script to stop it completing (and automatically closing the window), adding the line raw_input() to the last line in your script will cause the Window to stay open until Enter is pressed.
Try to open in Command Prompt instead of run window. The syntax is:
py filename.py
If it doesn't work, try to reconfigure Python. Did you set environment variables? If not, this could help you
I really like Geany for writing Python code. When I click F5, it opens system's default terminal window and executes the code there.
There is also a terminal inside Geany window, the bottom pane and the last tab. What I want is the code to be executed there. Is it possible?
After fiddling with the options, I found the way:
Right-click on terminal area and select "Preferences". It opens the general preferences window with Terminal tab opened.
There is an option: "Execute programs in the VTE". Checking this option does what I want.
if you are at the location of your file, just type python in that terminal.