Error running .py from Windows 7 command prompt - python

I am new to python and I have just installed python 2.7.3 on Windows. I will also install django so I need to execute a file named ez_setup.py. I know it seems like an easy question and answer can be found in internet, but this is not the case. I tried lots of things and tried what internet says, the problem is still there and I cant find the problem!
I follow all the steps that is explained in tutorials in order for Python to work properly. (Installing steps and editing environment variables..)
Python's location is:
C:\Users\name\27
Command prompt starts like:
C:\Users\name>
I have put ez_setup.py file under both C:\Users\name\27 and C:\Users\name.
When I type "ez_setup.py" or "python ez_setup.py" or "\27 python ez_setup.py" and lot of combination, it says:
python: cant open file 'ez_setup.py': [Errno 2] No such file or directory.
What should I do? Where do I make mistake?

Just do:
python ez_setup.py
You need to say your machine that it should execute this .py file with python.

Related

Python code invokes different interpreter from shell

During zerphyr rtos installation process i ran into this error https://pastebin.com/8F5A8S8m, which i safely brute-forced by the link given in the next sentence, but now same error but different file. And here is the code from that file https://pastebin.com/EawPKXRG. So, in short, by googling i couldn't find a way to change interpreter that python uses in this particular files.
FYI
which python
gives python 3.11 one
sudo su
nano etc/path
gives also right directory for python 3.11, but somehow these files use python 3.9 which is installed on this mac by default.'
p.s sorry for the grammar and structure, I'm so mentally drained now to write it properly.
Didn't find anything on google
So you need to run those python files in this format
python3.11 your_desired_file_name

"python.exe can't find '__main__' module in ..." Error when trying to run python script opencv_blink_detect.py in virtual environment,

Apologies if there's missing information. I'm using python for medical research and am trying to run a program to count the number of blinks via video footage.
https://github.com/skvrahul/blink_detect
The script is located here
My virtual environment is set up here:
Package install instructions were followed from here
Terminal open via Anaconda
Attempt to run via readme instructions
Attempt to direct terminal to look at file path
As you can see, the error message is
(opencv-env) C:\Users\wmj>python C:\Users\wmj\Documents\Python Scripts\Biometrics\blink_detect-master.py -p -sp.dat
C:\Users\wmj\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe: can't find 'main' module in 'C:\Users\wmj\Documents\Python'
The contents of C:\Users\wmj\Documents\Python is just Anaconda3-2018.12-Windows-x86_64
I have searched online and most solutions to this problem seem to be either solved by modifying the .py file or doing something with Pycharm
What is the solution to this? I want to be able to run the script as a demonstration to my supervisor
Thank you,
WW
Try first to cd to the exact location of the package and then run exactly as written in the readme instructions.
Python has to get the full path of the script you're trying to execute and the script itself has to get the sp.dat file as an argument.

Python File Directory Can't be found

When I try to run my python file, I get the following error: "can't open file 'hello.py': [Errno 2] No such file or directory" I have tried cd and it shows that my file is in the Users/ierdna/ directory. I have the python program on my desktop and I still cannot run it.
Thanks very much!
It seems that I have tried everything, and nothing is working. :(
I am going to assume you know some of the basic BASH command line commands. If you don't check them out here.
Opening your terminal's respective shell, enter the following on your command line:
cd Desktop [to change directory to your desktop]
ls [to list all the directories and files on your desktop, to make sure your hello.py file is in fact there]
python hello.py [to run your python file]
That should run it. Let me know if you run into errors.
In order to properly answer this question the following information are required:
a. OS that you are using
b. Release version of that OS
c. Python version that you are using
d. If your machine has at least 10GB of free space
Kidding!
You just need to use cd ~/Desktop to make the 'Desktop' your working directory and then try to run python hello.py Alternatively you can also try running python ~/Desktop/hello.py directly without using 'cd' command. Note: In order to run a python script you need to provide the path(Either complete path, for example: python /home/username/Desktop/script.py or relative path, for example: python ../script.py) to the script. If you just provide the script name, it will fail unless the script exists in the current working directory. Also, kindly do check for existing questions and answers before posting your own question as I doubt this question is new and hasn't been answered correctly before.
I'm going to assume from you saying you used cd that you are using Mac or Linux. This solution will work for both. If I am wrong and you are running Windows, just comment it and I'll change the answer. On to the real answer:
First open your terminal, then type cd ~/Desktop. Now try running your python script.
EDIT:
Apparently you are running Windows. OK. I'm going to leave the above answer for other people who have the same problem on Mac or Linux. What you need to do is execute this command in your command prompt cd C:\Users\[your user name]\Desktop. Replace [your user name] with your actual user name. Then run your python script (python hello.py)

Receiving ': No such file or directory' when trying to run my Python script for Baxter Robot in Ubuntu terminal

I'm very new to programming and I'm working with a Baxter Robot by Rethink Robotics.
I have been able to run other peoples' Python scripts through the terminal no problem.
I have created my own custom script using Sublime Text 2 and saved it as .py. However when I try to run it, I receive the ': No such file or directory' error. I have checked my code and it has an identical template (code structure) to the others that work.
My shebang is as follows:
#!/usr/bin/env python
I have compared the properties of the file to the others and they are exactly same, i.e it's definitely a Python file.
Have I missed something in Sublime? It's using the first version of Python but I'm under the impression that it shouldn't be the issue.
I'm using ROS Groovy and Ubuntu 12.04 LTS.
Sorry if this is a very basic question, I'm completely new to this and all the answers I have found have not helped.
Edit:
My command in Ubuntu terminal:
[baxter - http://localhost:11311] leigh#leigh-System-Product-Name:~/ros_ws$ rosrun baxter_interface hole_setup.py
Error:
: No such file or directory
If I change the Python script to onethatworks.py, it initiates fine.

running python executable in linux

I've found a few other people asking this question, but the answers for their problem are not helping me. I trying to learn python and trying to make a file executable.
The practice script runs when I type python ./userPrompt.py.
But when I try to run it as an executable (just ./userPrompt.py).
I've successful change it chmod +x
And here's what i have in the top line of the file:
#! /user/bin/env python
and here's the error I get
bash: ./userPrompt.py: /user/bin/env: bad interpreter: No such file or directory
But the thing is if I go to /user/bin I can find env. So it definitely exists. Why can't Ubuntu find it??
I appreciate any help people can give me on this.
The path is /usr, not /user.

Categories