Python 101 : Komodo edit - code not running in command - python

I have just opened up Komodo edit and can't run any code.
I just get this message in the command output:
/usr/bin/python: can't open file 'Python3-1.py': [Errno 2] No such file or directory
What do I do? I installed python3 again. Do I need to install it in the right place?

I think it say for you - I can't find your file.
You should try to check path to you file.
Then you should try to run your code from terminal. Open terminal app (gnome-terminal, konsole, xfce-terminal or etc. what you always using for this) and try run directly you file in you folder like this:
python Python3-1.py or python3 Python3-1.py or python3 -m Python3-1.py.
If all works fine - check you Komodo settings.Edit -> Preferences in Language block check in Python Default Python Interpreter
If not help you -please update you question for more information.
P.S. and you should try VS Code for python development. It have awesome integrated terminal and you can learing run all programs on command line, like you will do it in real life. Komodo Edit good editor, but not the best for this.

Related

Trying to run Python program from command prompt

Path must be messed up and I can't fix it.
In the command prompt I am trying to open and run a python program that I made in IDLE. I am running Python 3.8.5. According to Automate the Boring Stuff, I should just be able to do:
py birthdays.py
But when I do that I get:
C:\Users\name\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'birtdays.py': [Errno 2] No such file or directory
All of my scripts are located in: C:\Users\henri\AppData\Local\Programs\Python\Python38-32.
The only thing that I could think of is that it is going one step too far and searching in python.exe instead of just Python38-32. But Ii'm not even sure it works like that.
I tried to add the exact path using:
set PATH=%PATH%;C:\Users\name\AppData\Local\Programs\Python\Python38-32
But when I do this and press enter nothing happens.
when I want to use CMD to run python scripts, I just use
cd\
to back the main root of drive C. then use
cd folderAddress
for several time until to reach the exact scrip containing folder. Finally, I type
python scriptName.py
In your command prompt type python.The output should be python 3.** (depending on your python version).
If you see the python version it's working fine. In command prompt navigate to the folder that you have your python file using cmd command. then type
python birtdays.py
Don't forget the space after python.

Running Python Programs from a Terminal

I am working on page 16, chapter 1, in the book "Python Crash Course" by Eric Matthes. I am trying to run my hello_world.py python program from my Windows terminal.
The directions say to:
Open a new terminal window and issue the following commands to run hello_world.py:
C:\> **cd Desktop\python_work**
C:\Desktop\python_work> **dir**
hello_world.py
C:\Desktop\python_work> **python hello_world.py**
Hello Python world!
python_work is my python work folder on my desktop. In my Windows terminal, I have tried entering the code with and without the unbolded C:\>. It has given me an error message: The system cannot find the path specified. I'm probably doing something wrong, but I don't know what's wrong.
Assuming your getting your error when you execute "python hello_world.py", Python might not be installed correctly. More likely is that you are not in the correct directory. Do the following commands:
cd "C:\Desktop\python_work"
python hello_world.py
If that does not work, I can only assume one of two things:
Either the folder or the .py file is not named what you think it is and you should rename whichever one, or python is not installed correctly and you should reinstall it.
use
cd C:\Desktop\python_work
to change your working directory and then type
hello_world.py
to launch your program or if that doesn't work try
python hello_world.py
alternatively (what I do), assuming the first option worked, you can create a .bat file with the following code.
#echo off
"%~dp0\hello_world.py" %*
pause
and then just put that bat file in the same folder as "hello_world.py" and when you run the bat file it will launch the script. :)

Python curses Redirection is not supported

I am trying to use Curses in PyDev in Eclipse in Win7.
I have installed Python 3.2 (64bit) and curses-2.2.win-amd64-py3.2. When I input the following testing codes into PyDev:
import curses
myscreen = curses.initscr()
myscreen.border(0)
myscreen.addstr(12, 25, "Python curses in action!")
myscreen.refresh()
myscreen.getch()
curses.endwin()
It did not show any syntax error, so I think the curses was installed correctly.
However, when I ran it as Python Run, the output showed: Redirection is not supported. I do not know where this problem comes from. I googled a lot but can't find related information.
Recent PyCharm versions (I am currently running 2017.2, not sure when this option was added, or if it has been there the entire time) have the option "Emulate terminal in output console". Curses works with this option checked.
You cannot expect to use curses with a non-terminal.
Probably you get this because you are running the script from inside an IDE, like PyCharm or any other.
All IDEs do provide consoles that are not terminals, so that's where the problem comes from.
For a Pycharm user the solution given by codeape works fine :
Snapshot
You can't use any IDE to run python files with the curses package. I used to run in pycharm and naturally couldn't run.
Change to the command line to run:
for testing follow my following steps
on desktop open notepad and copy paste the code and save it as filename.py
open command line change directory to desktop use below command cd Desktop and hit enter type python example.py and hit enter, your program will definitely run
My workaround is to create a Run Configuration that calls a curses script. The little overhead is worth not having to switch to the terminal and manually run the script hundreds of times a session. I use Intellij but I imagine the process should be similar in PyCharm.
The desired result is the convenience of a button to run the script:
First create a script that calls the entry script, for instance:
ptyhon name-of-script.py
Then, to create a configuration for each script:
Go to Edit configuration.
Click the plus button and add a Shell Script.
Enter the path to a shell script.
Here is a picture of a directory with a couple of sample scripts.
I use this process to view my progress. My curses scripts are very modest so fortunately I can live without a debugger.

PyCharm: How to run behave.exe?

I want to use behave lib in my program. I write code as in behave-tutorial.
But, when I "Run" my tutorial-project, I see in PyCharm-console:
C:\Python27\virtualenv\Scripts\python.exe "C:/Program Files (x86)/JetBrains/PyCharmProjects/tutorial/steps/tutorial.py"
Process finished with exit code 0
I think what I must to use behave.exe for run my project:
C:\Python27\virtualenv\Scripts\behave.exe
How to get it?
You can configure your run as per your purpose please have a look to screenhots here:
taken from: http://automated-testing.info/t/bdd-framework-debug-testov-stepov/3392/3
Even though behave support is now in the Professional Edition, it's currently not in the Community Edition.
You can still call the behave module for a given feature directory.
Add a Python Run configuration, with no script and these options:
Interpreter options: -m behave
Working directory: path/to/feature/directory
I tinkered around with previous answers and got PyCharm CE 5.x working with Behave I have python 2.7 installed system-wide, and behave installed via PyCharm package management
Here is my run config:
Script: put dot (.) in here [this way PyCharm recognizes the configuration as valid and doesn't show red cross mark]
Working Directory points to the dirctory where .feature file is
Interpreter options: -m behave
For PyCharm Community 2016.3 on mac, setup a run configuration with:
Script: /usr/local/bin/behave
Script Parameters: path/to/feature/directory
Working Directory: path/to/project/directory
This way the run & DEBUG both work.
I have 2 features file (createX.feature and createY.feature) at feature directory but I want to select only 1
My configuration is
Script: createY.feature
Script parameters: --tags=#int --tags=#e2e
Interpreter options: -m behave
Working directory: $features_directory
The "Run" window shows this execution command
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 -m behave createY.feature --tags=#int --tags=#e2e
but pycharm chooses the other feature file :(
But if I run the command at a terminal window, the command works!!
Edit: I have changed the feature file I want to execute for a better understanding: I try to execute the last one following alphabetical order
Edit 2: Solved It seems that behave does not like to have "scratch" files for control tasks at steps directory ... Once I deleted them, that handsome configuration works!!

Running Python from the Windows Command Line

How do I run a Python file from the Windows Command Line (cmd.exe) so that I won't have to re-enter the code each time?
Wouldn't you simply save your Python code into a file, and then execute that file using Python?
Save your code into a file called Test.py.
And then run it?
$ C:\Python24\Python.exe C:\Temp\Test.py
If you don't want to install an IDE, you can also use IDLE which includes a Python editor and a console to test things out, this is part of the standard installation.
If you installed the python.org version, you will see an IDLE (Python GUI) in your start menu. I would recommend adding it to your Quick Launch or your desktop - whatever you are most familiar with. Then right-click on the shortcut you have created and change the "Start in" directory to your project directory or a place you can mess with, not the installation directory which is the default place and probably a bad idea.
When you double-click the shortcut it will launch IDLE, a console in which you can type in Python command and have history, completion, colours and so on. You can also start an editor to create a program file (like mentioned in the other posts). There is even a debugger.
If you saved your application in "test.py", you can start it from the editor itself. Or from the console with execfile("test.py"), import test (if that is a module), or finally from the debugger.
If you put the Python executable (python.exe) on your path, you can invoke your script using python script.py where script.py is the Python file that you want to execute.
Open a command prompt, by pressing Win+R and writing cmd in that , navigate to the script directory , and write : python script.py
A good tool to have is the IPython shell. Not only can it run your program (%run command), but it offers also many tools for using Python interactively in an efficient manner (automatic completion, syntax coloring, quick access to the documentation, good interaction with Matplotlib,…). After you install it, you'll have access to its shell in the Start menu.
You need to create environment variables. Follow the instructions here: http://www.voidspace.org.uk/python/articles/command_line.shtml#environment-variables
In DOS you can use edit to create/modify text files, then execute them by typing python [yourfile]

Categories