I'm using cygwin on windows 7 to run a bash script that activates a python script, and I am getting the following error:
myscript.script: /cydrive/c/users/mydrive/folder/myscript.py: usr/bin/env: bad interpreter: Permission Denied.
I'm a total newbie to programming, so I've looked around a bit, and I think this means Python is mounted on a different directory that I don't have access to. However, based on what I found, I have tried to following things:
Change something (from user to exec) in the fstab: however, my fstab file is all commented out and only mentions what the defaults are. I don't know how I can change the defaults. The fstab.d folder is empty.
change the #! usr/bin/env python line in the script to the actual location of Python: did not work, same error
add a PYTHONPATH to the environment variables of windows: same error.
I would really appreciate it if someone could help me out with a suggestion!
In my case the problem was in the missing executable flag on the file.
The solution for me was in the following code
chmod +x ./executed_file
You script should start with:
#! /usr/bin/env whateverelse ...
^ this first one is important
This seems to be a late answer, but may be useful for others. I got the same kinda error, when I was trying to run a shell script which used python. Please check \usr\bin for existence of python. If not found, install that to solve the issue. I come to such a conclusion, as the error shows "bad interpreter".
I would recommend you to 'run cygwin as administrator' Thanks.
EDIT:- try chmod for permissions read for more here
You should write your command as 'python ./example.py ',then fix it in your script.
This was in Git Bash for me. I changed the first line (shebang line) of the .py file being run, leaving the original, adding the one above it, and that worked:
#!python
#!C:\Users\Emiri\Anaconda\envs\_build\python.exe
("Emiri" doesn't exist on my system, was hardcoded in a zipline install)
In my case I used cmder and started bash as Admin instead of WSL
You can disable SELinux by using:
setEnforce 0
More info about how to use SELinux
Related
I wrote some code on my laptop and now I am trying to run this code. But it give me the output : Permission denied
Usually that should only happen if a different user would try to access it. But I am the user who wrote it and is trying to run it now. I feel like this will be an easy issue to resolve but any help would be nice! Thanks.
I wrote and saved the code in IDLE python. Once I finished I tried running it in my Terminal (I have the macOS Mojave Version 10.14.5) but then I ran into the issue.
Evandros-MBP:~ evandro$ ./Desktop/FunCodes/pwd.py
This is how I tried to call up the code. I don't see any issues here.
Instead of calling the script with
./Desktop/FunCodes/pwd.py
try using
python ./Desktop/FunCodes/pwd.py
or also
python3 ./Desktop/FunCodes/pwd.py
if you want to execute it with python3 instead of python2.
Explanation
When you write ./some-file in the terminal (without writing python before the file path), the terminal executes it as a bash file (no matter if the file has a .sh extension or not). Of course, since your file is a python file, this will fail. But even before it fails, since your python file has no permission to be executed, permission will be denied and bash won't even start.
On creation, the file only has read and write permissions. Add a shebang pointing to the Python interpreter on the script's first line, for example #!/usr/bin/env python. Also, your script is not marked as executable, in order to do that you need to use:
chmod +x pwd.py
Otherwise you will only be able to run it with Python, with
python pwd.py
Please help me. I have spent so many times for it but still don't know why.
First of all, I would like you to know that I am really new to programming and don't know well about basics.
Also sorry for my english which probably confuses you all.
I have created the venv on Pycharm (Windows 10, python 2.7 installed).
And my workspace is located on VM (Linux Centos6.1, python 2.6 by default)
I access my vm by Samba interface.
When I created venv and executed my script, I saw console said that it exceucted python.exe(2.7 version) on my venv.
So I thought, if I would move to the whole venv directory to my vm linux ,
I could run my scripts by python2.7.
But when I treid it on another VM CentOS 5.11, the result was
$> source myvenv/Scripts/activate
[venv]$> ./myscript
./hello.py: line 1: import: command not found
./hello.py: line 2: import: command not found
./hello.py: line 3: import: command not found
: command not found
: command not found
./hello.py: line 6: syntax error near unexpected token `'imported all successfully.''
./hello.py: line 6: `print('imported all successfully.')'
So I figured out it was still using python2.4 (defualt of centos5.11).
Then I googoled and tried some solutions, one of those was to change my VIRTUAL_ENV variable since it was created on Windows10.
vi myvenv/Script/activate
VIRTUAL_ENV="$(if [ "$OSTYPE" "==" "cygwin" ]; then cygpath -u
'${myWindowsVenvPath}'; else echo
'${myLinuxVenvPath}'; fi;)"
export VIRTUAL_ENV
but still doesn't work..
(Tried shebang #!/myvenv/Scripts/python in my script as well)
I guess Probably I don't understand vevn concept well.
Did I try worng? If there is any suggestion to solve it, or I have apporoached wrong, please let me know.
Thank in advance for your opinion.
revision >
my script is just for checking if the third-party modules could be imported.
(before I move to my whole script to around venv)
so it is like this below,
import pandas
print('it's working') --> to check if python2.7 is running since it has the different syntax for print function.
I found out the reason myself.
What I got until now is the binary file :python.exe is subordinative to operating system.
So I made venv on linux again, then it seems to work on the diffrecnt version of linux, which means the upper version of python can be excuted in venv (prerequsite: it needs libpython2.6.so as well)
still remains alot of shared libraries issue...so the conclusion is that I have approached totally wrong.
To start off, I am a complete noob to Debian, Python, and shell scripts, so please speak to me like I am a toddler.
I have a python script I am running through a virtualenv, and I want to execute it via a shell script. Here is what I'm typing in to the terminal to do so:
source .profile
workon cv
cd Desktop/Camera
python main.py
I tried turning this into a shell script, but I receive the error -- source: not found
I've found no answer to my problem, at least not in any terms I can understand. Any advice would be appreciated. Furthermore, before you answer, I also have no idea why it is I need to execute source .profile, I'm simply following a beginner guide for the project which can be found here: https://www.hackster.io/hackerhouse/smart-security-camera-90d7bd
Thanks in advance, and sorry if this is a dumb question.
Best practice for Shell would be shebang at the begging like #Veda suggested.
Execute the shell script using bash like bash shell.sh as the link suggests using relative locations rather than absolute ones
Add a hashbang at the top of your script (should be the first line):
#!/bin/bash
This will ensure you are running your shell-script in bash. Having a shell does not mean it's bash. Not all shells have the source function that you are using (bash has it).
Some prefer the following:
#!/usr/bin/env bash
Since you are a "beginner" I think it does not really matter. The first makes sure it's using the bash in /bin, the second is using the PATH variable to find bash, so the user of your script can provide it's own bash if he/she wants.
I am trying to run the basic helloworld code described here https://cloud.google.com/appengine/docs/python/. However, whenever I try the dev_appserver.py helloworld/ command, I get a usage error for the dev_appserver.py command.
I have installed Python 2.7 and also have Python 2.7 Anaconda installed on my system. Could the Anaconda Python be the cause of the issue?
The file structure of my code is as follows:
Project
helloworld
app.yaml
helloworld.py
README.md
I have tried executing the dev_appserver.py helloworld/ command from inside the 'Project' folder and the 'helloworld' folder. But I get the same error in both cases.
Any help would be greatly appreciated!
Thanks!
I think I have found the "real" problem behind this error.
Tried putting some print statements in the dev_appserver.py file and found that what ever argument we are giving is not being passed and hence the error. On googling came across this SO post which explains the problem. On doing that change the following command worked flawlessly :D
dev_appserver.py app.yaml
Quoting that SO answer for easier reference:
I think I solved this. For some reason there is a SECOND place in the registry (besides that shown by the file associations stored in HKEY_CLASSES_ROOT\Python.File\shell\open\command):
[HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command]
#="\"C:\\Python25\\python.exe\" \"%1\" %*"
This seems to be the controlling setting on my system. The registry setting above adds the "%*" to pass all arguments to python.exe (it was missing in my registry for some reason).
You just need to execute the dev_appserver.py with path to app.yaml in the command itself, as suggested in comments.
I think OP could've identified a potential issue when describing multiple Python installations.
If I don't specify which Python installation (I thought I only had one...), then, it fails:
C:\Python27>"C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" "C:\users\jessmine\documents\ttbtamer\app.yaml"
usage: dev_appserver.py [-h] [-A APP_ID] [--host HOST] [--port PORT]
...etc...
dev_appserver.py: error: too few arguments
But if I specify which Python to use by invoking Python first, # C:\Python27\python.exe, then it works:
C:\Python27>"C:\Python27\python.exe" "C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py" "C:\users\jessmine\documents\ttbtamer\app.yaml"
INFO 2016-11-18 10:09:14,299 devappserver2.py:769] Skipping SDK update check.
Anyway since I don't think I have other Python installations on my computer, then I may be misinterpreting the difference here. But for me, the fix is to explicitly invoke python.exe.
(And to be clear, I know about putting the Python.exe location into %PATH%, but I expected that if it wasn't there, that the error would've been something like "'dev_appserver.py' is not recognized as an internal or external command", rather than executing and printing a Python error....)
EDIT
After changing the "associate a file type or protocol with a specific program" (example here) for *.py to explicitly use C:\Python27\python.exe , then I no longer needed to manually invoke C:\Python27\python.exe in my cmd; i.e. my first example worked correctly :
C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin>dev_appserver.py "C:\users\jessmine\documents\ttbtamer\app.yaml"
INFO 2016-11-18 10:33:50,269 devappserver2.py:769] Skipping SDK update check.
I had the same problem. I even installed everything on a fresh machine and I was getting the same error again.
So I "debugged" dev_appserver.py and I discovered that the argument passed to it (i.e. 'app.yaml' or '.' or '\hello_world') was not passed down to the following code file:
...\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\devappserver2.py
In this file the arguments were checked, producing the infamous error "too few arguments".
Out of desperation for the time lost, I made a quick (and for sure ugly) patching.
I commented out at lines 302 and 303 the validation rule:
parser.add_argument(
'config_paths', metavar=arg_name, nargs='+', help=arg_help)
At line 758 I replaced:
options.config_paths, options.app_id)
with a static file name:
{'app.yaml'}, options.app_id)
At least now I am able again to start the server and develop my application. Now that I can work again, I will try to understand better how to correct the problem.
I'm not a Python nor a Google App Engine expert, so I hope someone will propose a better correction and a better explanation of the problem, because I cannot believe that Google can release such bugged code!
I suggest cd into your helloworld folder and and run dev_appserver.py . don't forget the ending dot '.' sign.
Hope it works
In my case I was able to resolve this issue by peforming following two actions:
1). added "python" in the start of the command
2). provided full path to the "dev_appserver.py" file.
So in Google docs you will find to execute the following:-
> dev_appserver.py ./ --php_executable_path=/path/to/php-cgi
(note that I was trying to run the php example and on windows environment here...)
Instead running the following command worked:
> python "c:\<path to the directory containing the dev_appserver.py script>\dev_appserver.py" ./ --php_executable_path=/path/to/php-cgi
I normally program in Java, but started learning Python for a course I'm taking.
I couldn't really start the first exercise because the command
python count_freqs.py gene.train > gene.counts
didn't work, I keep getting "incorrect syntax" messages. I tried solving this looking at dozens of forums but nothing works, and I'm going crazy.
import count_freqs
ran without errors, but I can't do anything with it. When I try running something involving the file gene.train I get "gene is not defined".
Can anyone tell me what I'm doing wrong? Thanks.
type which python at the command prompt to see if the python executable is in your path. If not it either isn't installed or you need to amend your path to include it.
on Windows you can type echo %%PATH%% at the command prompt. It will give you at list of all the directories the shell search for programs to run. By default Python 3.3 will be installed on C:\Python33.