shebang

env: python\r: No such file or directory

喜夏-厌秋 提交于 2019-11-30 10:32:38
问题 My Python script beak contains the following shebang: #!/usr/bin/env python When I run the script $ ./beak , I get env: python\r: No such file or directory I previously pulled this script from a repository. What could be the reason for this? 回答1: The script contains CR characters. The shell interprets these CR characters as arguments. Solution: Remove the CR characters from the script using the following script. with open('beak', 'rb+') as f: content = f.read() f.seek(0) f.write(content

Is there a standard way to make sure a python script will be interpreted by python2 and not python3?

白昼怎懂夜的黑 提交于 2019-11-30 08:22:09
Is there a standard way to make sure a python script will be interpreted by python2 and not python3? On my distro, I can use #!/usr/bin/env python2 as the shebang, but it seems not all distros ship "python2". I could explicitly call a specific version (eg. 2.6) of python, but that would rule out people who don't have that version. It seems to me that this is going to be increasingly a problem when distros will start putting python3 as the default python interpreter. This is a bit of a messy issue during what will be a very long transition time period. Unfortunately, there is no fool-proof,

How to execute a java script with jshell?

折月煮酒 提交于 2019-11-30 01:48:57
Given that Java 9 is upon us and we can finally have a java REPL with jshell I was hoping there was a way to add a shebang to a script and have jshell interpret it. I tried creating test.jsh : #!/usr/bin/env jshell -s System.out.println("Hello World") /exit However that gives: ⚡ ./test.jsh | Error: | illegal character: '#' | #!/usr/bin/env jshell -s | ^ | Error: | illegal start of expression | #!/usr/bin/env jshell -s | ^ Hello World It turns out there is an enhancement request for this in OpenJDK https://bugs.openjdk.java.net/browse/JDK-8167440 . Is there any other way to do this? Use //usr

what is the use of “#!/usr/local/bin/ruby -w” at the start of a ruby program

假如想象 提交于 2019-11-29 22:57:44
what is the use of writing the following command at the start of a ruby program ? #!/usr/local/bin/ruby -w Is it OS specific command? Is it valid for ruby on windows ? if not, then what is an equivalent command in windows ? The Shebang line is optional, and if you run the ruby interpreter and pass the script to it as a command line argument, then the flags you set on the command line are the flags ruby runs with. A Shebang line is not ruby at all (unless you want to call it a ruby comment). It's really shell scripting. Most linux and unix users are running the BASH shell (stands for Borne

env: python\\r: No such file or directory

折月煮酒 提交于 2019-11-29 20:52:25
My Python script beak contains the following shebang: #!/usr/bin/env python When I run the script $ ./beak , I get env: python\r: No such file or directory I previously pulled this script from a repository. What could be the reason for this? falsetru The script contains CR characters. The shell interprets these CR characters as arguments. Solution: Remove the CR characters from the script using the following script. with open('beak', 'rb+') as f: content = f.read() f.seek(0) f.write(content.replace(b'\r', b'')) f.truncate() Open the file in vim or vi, and administer the following command: :set

Why doesn't virtualenv on Windows associate .py/.pyw/.pyo/.pyc files with virtualenv's version of Python executables?

狂风中的少年 提交于 2019-11-29 19:55:12
问题 What is the reason virtualenv does not associate .py(w) files with virtualenv's version of Python executables? This seems like an ideal task for virtualenv on Windows taking into consideration that there's no mechanism like shebang on Windows. 回答1: File type associations are handled in the Windows registry. The virtualenv activate script would have to modify the registry keys and the deactivate script would need to restore the previous value (or risk breaking the associations). What happens

What's the difference between these two python shebangs

血红的双手。 提交于 2019-11-29 19:40:11
I used to use the shebang #!/usr/bin/env python When is it better to use #!/usr/bin/python What is the exact difference between them? vartec #!/usr/bin/python is hardcoded to always run /usr/bin/python , while #!/usr/bin/env python will run whichever python would be default in your current environment (it will take in account for example $PATH , you can check which python interpreter will be used with which python ). The second way ( #!/usr/bin/env python ) is preferred , as it's not dependent on particular installation. It will work for example with virtualenv setups or systems where there is

Is there a standard way to make sure a python script will be interpreted by python2 and not python3?

穿精又带淫゛_ 提交于 2019-11-29 11:06:16
问题 Is there a standard way to make sure a python script will be interpreted by python2 and not python3? On my distro, I can use #!/usr/bin/env python2 as the shebang, but it seems not all distros ship "python2". I could explicitly call a specific version (eg. 2.6) of python, but that would rule out people who don't have that version. It seems to me that this is going to be increasingly a problem when distros will start putting python3 as the default python interpreter. 回答1: This is a bit of a

Shebang doesn't work with python3

孤人 提交于 2019-11-29 06:40:34
问题 I have the following program: #!/usr/local/bin/python3 print("Hello") Via terminal I do test.py and I get: Traceback (most recent call last): File "/usr/lib/python3.3/site.py", line 629, in <module> main() File "/usr/lib/python3.3/site.py", line 614, in main known_paths = addusersitepackages(known_paths) File "/usr/lib/python3.3/site.py", line 284, in addusersitepackages user_site = getusersitepackages() File "/usr/lib/python3.3/site.py", line 260, in getusersitepackages user_base =

Make Node.js support the shebang (#!) for JavaScript files

折月煮酒 提交于 2019-11-29 03:03:53
Some scripting languages (such as Python or Bash) use # for comments. #!/usr/bin/env python print 'hello, world' I can run the script: python script.py Or ./script.py Is it possible to make JavaScript support shebang? Yes, you can simply use #!/usr/bin/env node (or whatever the name of your JavaScript interpreter is, it works fine with js (spidermonkey), too). [me@hades:~]> cat > test.js #!/usr/bin/env node console.log('hi'); [me@hades:~]> chmod +x test.js [me@hades:~]> ./test.js hi Most likely both interpreters test if the first line begins with #! and in this case it is skipped. 来源: https:/