I am following this guide for python 2.7 :
http://docs.python.org/tutorial/interpreter.html
I do all it says: I have a python file:
#! /usr/bin/env python
print "hello world !\n"
And from terminal, in the directory where is the file I type:
chmod +x hello_world.py
The file is name hello_world.py; But nothing happens, it doesn't print "hello world\n".
sorry if this is insultingly obvious, but
> chmod +x hello_world.py
only changes the file so that you can run it. next you need to actually run the file by typing:
> ./hello_world.py
hello world !
To give a bit more description: the chmod command changes the permissions of a file on a Unix-style system. The +x in the command:
chmod +x hello_world.py
Sets the "Executable" bit for the hello_world.py file, thereby making it a script which can be executed. Thus to run the script:
./hello_world.py
The ./ in front indicates that the file is in the current directory. Alternatively, you can always run a script by invoking the python interpreter directly (regardless of permissions) like so:
python hello_world.py
Related
My docker file looks like this:
WORKDIR $BUILD_OUTPUT_DIR
ENV TEMPLATECONF=$BUILD_INPUT_DIR/$PROJECT/sources/meta-$PROJECT/custom
COPY prep.sh /home/$USER_NAME/yocto/input/
COPY fetch-repos.sh /home/$USER_NAME/yocto/input/
USER root
RUN chmod +x /home/$USER_NAME/yocto/input/prep.sh
RUN chmod +x /home/$USER_NAME/yocto/input/fetch-repos.sh
RUN ls -l /home/$USER_NAME/yocto/input/*.sh
CMD ["sh","-c", "./home/$USER_NAME/yocto/input/prep.sh && bitbake $PROJECT"]
I run the container like this in azure ACR:
- task: Docker#2
inputs:
containerRegistry: '2460-ACR-connection-TMM'
command: 'login'
- script: |
docker run 2460testacr.azurecr.io/2460testacr.2460testacr.azurecr.io:$(tag)
But I have got this error, would you help?
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/cce02da3-0534-40a8-81c5-52ed45134050.sh
sh: ./home/rtr2460/yocto/input/prep.sh: No such file or directory
./root/prep.sh: No such file or directory
Tells you that the file at that location does not exist or the user has no access rights to that location. You will need to find the exact location where this path is being assumed in your configuration tries to use this path. It is either legitimate or not.
If it is legitimate, then there are two possibilities: it is either missing or your user does not have the necessary privileges.
If it is a privilege problem, then you can add a line that adds the necessary privileges. Otherwise, if it is missing, then you will need to find out why it is missing. Chances are that your
COPY prep.sh /home/$USER_NAME/yocto/input/
line is copying the file to the wrong location.
Otherwise, if it is illegitimate, then there is a bug in your configuration (that you can find by searching for anything related to this filename) and fix it.
I'm having trouble running a .sh file in python. When I type in the location of the .sh file (/home/pi/file/script.sh) the script runs perfectly.
I'm trying to run this script in my python2 script and I've done the following methods:
subprocess.Popen(['bash', 'location of .sh'])
subprocess.call(['location of .sh'])
os.popen(['location of .sh'])
When I run the python script, I get a prompt from rclone saying "Command sync needs 2 arguments maximum"
My .sh file just includes:
#!/bin/sh
sudo /usr/local/bin/rclone -v sync /home/pi/some_project_data remote:rclone --delete-before --include *.csv --include *.py
I'm not sure how running the .sh file on terminal works fine, but this error pops up when I'm trying to run the .sh file using Python.
Your script fails whenever you run it in a directory containing 2 or more .csv or .py files. This is true for terminals as well as via Python.
To avoid that, quote your patterns so the shell doesn't expand them:
#!/bin/sh
sudo /usr/local/bin/rclone -v sync /home/pi/some_project_data remote:rclone \
--delete-before --include "*.csv" --include "*.py"
Please try:
os.popen('bash locationof.sh')
ex:
os.popen('bash /home/script.sh')
That worked on my machine. If you place square brackets around the string then python assumes it is a list and popen doesnt accept a list, it accepts a single string.
If the script doesnt work, then this won't fix that, but it will at least run it. If it still doesnt work, try running the script with something like
touch z.txt
and see if z.txt appears in the file explorer. If it does, then your .sh file has a problem.
How do you configure Tox to source a file before it runs your test command?
I tried the obvious:
commands = source /path/to/my/setup.bash; ./mytestcommand
But Tox just reports the ERROR: InvocationError: could not find executable 'source'
I know Tox has a setenv parameter, but I want to use my setup.bash and not have to copy and paste its contents into my tox.ini.
tox uses exec system call to run commands, not shell; and of course exec doesn't know how to run source. You need to explicitly run the command with bash, and you need to whitelist bash to avoid warnings from tox. That is, your tox.ini should be somewhat like this:
[testenv]
commands =
bash -c 'source /path/to/my/setup.bash; ./mytestcommand'
whitelist_externals =
bash
I am new to Python and learning to program in it.
I wrote a basic script
my.py
#! /bin/python
print "hello world!"
but this does not execute.
I did
chmod +x my.py
and
./my.py
I have tried removing the blank space in my program
#!/bin/python
but even this gives me error
bash: ./my.py: /bin/python: bad interpreter: No such file or directory
I am using Ubuntu 12.04 and Python is present on system.
I have checked the program by typing on terminal
So what could be the problem here?
The error means there is no file at the path /bin/python
Try which python to see the location of the interpreter
But why not python my.py?
I read I document provided but can't understand how to use shedskin, I'm not experienced at python.
I have python 2.7, I test it seems it works in cmd, or if I just double click on .py file it produce .pyc file.
I run tests in shedskin\shedskin-0.9.1\shedskin\tests by clicking run.py it produce some .cpp and makefile, but I can't understand how to run it on my .py files?
mkdir helloworld
cd helloworld
echo -e "import sys\nprint 'hello '+sys.argv[1]" > helloworld.py
python helloworld.py this_is_python
shedskin helloworld
make
./helloworld this_is_c_plus_plus