Getting a python3: can't open file and Errno 2 Error after code successfully running on iMac - python

I am a beginner coder who is moving from pycharm over to sublime text. From what I understand you can run programs in the command line or in terminal and I want to make sure I can do both. When I try to run my file by inputting "python 3&5Multiples.py" it runs the program and outputs this response. Ignore the first line as that is my input, I included it because it may be helpful to understand what is going on.
MyiMac-iMac:py ianbridges$ python 3&5Multiples.py
[1] 71175
-bash: 5Multiples.py: command not found
MyiMac-iMac:py ianbridges$ /Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file '3': [Errno 2] No such file or directory
How do I make it so this text never appears and I just get the output of the program? Thanks!

As per your shell command, anything after the & is considered as a separate command. So, in order to tell the shell that you want it to be considered entirely as one term, you must use double-quotation marks. So, you can edit your command like so:
$ python "3&5Multiples.py"
PS: Don't include $ in the command

Related

Unablle to use stdin in Python with Ubuntu

I have previously worked with python 3 in Windows 10 where I prefer using this for reading input and output from my files. This is the syntax I use
import sys
sys.stdin = open("input.in", "r")
sys.stdout=open("output.txt","w")
Input.in -> for input Output.out for Output
Now that I have shifted to Ubuntu I find it difficult to read input via Input.in, I created this input.in file using this command in vim
sudo vim input.in
wq
And now that I am using this file to read any Inputs, I get this error very often
File "", line 1
I faced no issues with Windows 10.
I donot know the reason for it But Maybe , I am not able to rightly Make my Input.in File correctly in Ubuntu, If please some one can explain me the issue and tell me the reason for this behaviour.
I understand the error you are facing just use the command mkdir to create a folder then rename it accordingly with .txt and you will be able to do it. do not use sudo bro.

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.

How do I use the cmd to run a python program written in Spider

So I have gone into the cmd and found where my file I want to run is located. It is called 3.py and my teacher had told us just to write "python 3.py" to run it. I did this and it doesn't say that there is anything wrong, it just does nothing. Almost like there is nothing to be read in the file 3.py. But I open it just to make sure I'm not just trying to run an empty file. My file has something simple in it like print("Hello there, this program is working") so I know it isn't not running because of an error in the code.
I am using spider from anaconda to write my code into.
I have found out how to do it now. You have to use Anaconda prompt rather than cmd.

Issue with Python Batch file to run Python through Notepad++

EDIT: The code I wrote in my Python file was just this:
print "foo"
I'm using Windows XP Home Premium on this tiny little HP Mini 1000, and I want to run Python files, since we're learning it in school. I am aware of this topic, so I tried to run Python files using a batch file (python.bat), and I'm getting an error that says, "Can't find 'main' module in ''" whenever I run the batch file. I followed the instructions given here. All I did was change "Python26" to "Python33" because of the difference in versions.
Any idea what's wrong here? I really want to run Python files from Notepad++, so I don't want any alternative ways to run them.
This sounds like you don't have PYTHONPATH set up correctly. I suggest you review the documentation here:
http://docs.python.org/2/using/windows.html
Instead of calling Python, call cmd.exe and then use the set command to inspect which variables are set and how they are set. Run the exit command to leave the command shell. When you think you have the variables set up correctly, try again to run Python.
Good luck and have fun!
I use the command line interpreter or IDLE mostly (Win 8.1 now, but I've done so since Win XP SP2), but NPP is my main text editor, so I was curious about this issue.
When I was reproducing this, I was able to generate several errors, but the only one I got that was an exact match was when I failed to configure the Run option correctly.
You need to make sure to follow this step exactly in the instructions you were following. When you navigate to Run -> Run in Notepad++, you have to enter this exactly:
C:\Python33\python.bat "$(FULL_CURRENT_PATH)"
I am pretty sure you left out the "$(FULL_CURRENT_PATH)", or otherwise didn't add it correctly, as failing to do so causes exactly the same error on my end. Failing to include this means that when you run the batch script, you get the wrong input to the Python interpreter, causing the error.

Permission denied for Python script using Bash?

I am new to Ubuntu... I am trying to run my first simple python program "Hello World" ...
After running following commands in terminal
1. chmod +x filename.py
2. ./filename.py
terminal is showing following error "bash: ./filename.py: Permission denied"
what can I do for solve about problem?
Do you have the appropriate incantation at the top of your python file? e.g.,
#!/usr/bin/python (or alternatively #!/usr/bin/env python)
Just to clarify, chmod +x only makes a file executable, it doesn't run it.
And I'm assuming your script looks like nothing more complex than this:
#!/usr/bin/env python
print 'hello world'
Some possibilities:
What does it say if you type umask? chmod +x will only make a file executable for you if your umask doesn't block the user executable bit. A typical umask such as 0022 will not block the user execute bit, but a umask like 0122 can. (See the Description section of chmod(1) for more info.)
To execute a script such as a Python script, you also need read permission. Try chmod u+rx filename.py and execute the script again.
It's also remotely possible that whatever interpreter you've specified in the file with the "hashbang" line at the beginning of your file (e.g. #!/usr/bin/env python) isn't executable, although that in my experience yields a different error message.
I deal with the same problem on my new system.
It is the third time I tried to solve this, and your post is the first one appearing on google results. My post is late, but think that it will help another users with the same problem.
In my case, it was about partition table setup.
Check in your /etc/mtab file how python script is being stored. Check if there is a clause: noexec
noexec is a flag that forbid executing under the partition. By default, it is set with exec. But, sometimes, this kind of things happen.
Now, it is working fine here.

Categories