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
Related
I'm trying to deploy a larger python project which includes a script on
windows. Installation works fine on UNIX, but on windows it seems
impossible to get the script running. I've created a minimal example on
GitHub to demonstrate
the problem.
When running pip install ., the script is installed to C:\Program Files\Python39\Scripts\hello-world. The directory is contained in the
PATH. My user has read & execute permissions. The hashbang of
hello-world is replaced with #!c:\program files\python39\python.exe,
which also seems correct. However, running hello-world in the console
yields the following error:
C:\Users\malte>hello-world
'hello-world' is not recognized as an internal or external command,
operable program or batch file.
I expected this to work. Why doesn't it? How can I fix this?
I've tried some things, and noticed another strange behavior in this
context. Running shutil.which('hello-world') returns None. If I
rename hello-world to hello-world.exe, then calling hello-world
results in a strange error, most likely because windows
now thinks the script is a binary. That's fine. Except that now
shutil.which('hello-world')
returns 'C:\\Program Files\\Python39\\Scripts\\hello-world.EXE'. Why?
Update
The master branch of the respository now contains a solution that works cross-platform, which I learned from here: https://matthew-brett.github.io/pydagogue/installing_scripts.html.
It's not exactly clear to me, but the following paragraph from the Python documentation seems to state that a script with a hashbang line must have an extension associated with the python launcher in order for windows to recognize it: https://docs.python.org/3/using/windows.html#from-a-script
In other words, it appears that my assumption that using the scripts parameter of setuptools.setup works cross-platform is subject to some conditions which are hidden somewhere in the python documentation.
I´m trying to execute locally installed programs from a Python script (OSX), but they are not found, since /usr/local/bin is not in the PATH. Running os.environ gives only /usr/bin:/bin:/usr/sbin:/sbin.
It is probably a common/simple problem, but I´ve exhausted Google, and start feeling a little stupid :-)
How do you try to execute your programs (please provide us a minimal code sample)?
If you are using the subprocess package, you can try to provide the full path of your executable:
subprocess.run(["/usr/local/bin/my_program"], ...)
Else, you can try to append /usr/local/bin to the os.environ list.
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)
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.
I'm slowly migrating from PHP to Python. In particular, as I work in webdev/webdesign I would like to display a basic HTML page using Python, using the following code:
#!/usr/bin/python
print('<html><head></head><body>This is a test</body></html>')
Sending the file online on my host as index.cgi, I've had no problem displaying the content of the file.
The problems start when I try to install the WSGI module on MAMP, or just to make Python work in general with it.
When it go to localhost/index.cgi the content of the file is displayed instead of its results.
I've followed half a dozen tutorials and none seems to work, I always encounter a problem at one point or another. It seems to come from the fact that Apache that comes with MAMP isn't built in a way that lets you add modules to it (such as wsgi).
This is also comes from the fact that I can't find any recent article on how to install Python on MAMP, they all either date from 2008 or 2009, with old versions of MAMP, Python and Macports.
Can somebody points me to the current procedure to make this work ?
EDIT : Ok after finding this article I gathered that MAMP by default don't process CGI scripts outside of the cgi-bin/ folder in MAMP/. So I modified the Apache conf file as explained, it now apparently reads the .cgi file but throws an error 500 with the content shown above. Is the code the culprit or is it MAMP's ?
Got it to work, the problem were the missing CGI interpretation of MAMP outside of the cgi-bin/ folder (see original post) and the missing headers :
print 'Content-type: text/html\n\n'
I've just gone through this process on OSX Catalina with Mamp V5.5
For me I had to follow the following steps:
Make sure your file has the first line:
#!/usr/bin/python
or a path to any valid Python installation or environment. Make sure your python is working correctly.
The file must have the extension cgi e.g.
blah.cgi (not .py)
Then it will work from any folder.
The file must have execute permissions. In terminal:
chmod 755 blah.cgi
The file must send a content type near the beginning ( no brackets for Python versions < 3 ):
print('Content-type: text/html \n\n')
An additional step I would recommend is adding this at the beginning of your page:
import sys
sys.stderr = open("err.log",'w')
Which will route all your error messages to the file err.log in the same directory which is insanely useful for debugging. If your page comes back with 500 Internal Server Error, you should see some errors in err.log file (unless the problem was in initial imports before this statement).
There are other config changes you can make to keep the .py extension but I won't go into that here.
This is just standard CGI, nothing special here, no need for WSGI. You do need to install Python. You can install it wherever you like, as long as your script can find it. You see the line:
#! /usr/bin/python
that is where the script will try to find Python, so change it to your Python installation, or fix your Python installation to be there.