shebang

How to make the Shebang be able to choose the correct Python interpreter between python3 and python3.5

北城余情 提交于 2019-12-30 06:40:31
问题 I'm developing a set of script in python3, as shebang I use this: #!/usr/bin/env python3 Everything goes ok, but in some virtual machines where are executed the name of interpreter is python3.5 . I will like to be able to execute my scripts in both enviroment but I can't change the filesystem of virtual machine (so I discard solutions like make a link from python3.5 to python3 ) I look at man of env but I don't find any way to specify a searching pattern or something like that. I try to set

How do I activate a conda env in a subshell?

让人想犯罪 __ 提交于 2019-12-28 06:59:27
问题 I've written a python program. And if I have a shebang like this one: #!/usr/bin/python and I make the file executable with: $ chmod 755 program.py I can run the program like so: $ ./program.py Here is the issue. I use the conda virtual environments. When I run the program like above, the system creates a subshell that does not recognize the active environment: (my_env) $ ./program.py ImportError: No module named pymongo If I do it this way, however... (my_env) $ python program.py # blah blah

Python source header comment

蹲街弑〆低调 提交于 2019-12-23 08:00:07
问题 What is the line #!/usr/bin/env python in the first line of a python script used for? 回答1: In UNIX and Linux this tells which binary to use as an interpreter (see also Wiki page). For example shell script is interpreted by /bin/sh . #!/bin/sh Now with python it's a bit tricky, because you can't assume where the binary is installed, nor which you want to use. Thus the /usr/bin/env trick. It's use whichever python binary is first in the $PATH . You can check that executing which python With the

How to get the script path of a python process who's cmdline is [“python”], with no path?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 18:45:11
问题 I'm trying to get and kill all other running python instances of the same script, I found an edge case where the path is not in psutil's cmdline list, when the process is started with ./myscript.py and not python ./myscript.py the script's content is, note the shebang: #!/bin/python import os import psutil import sys import time for proc in psutil.process_iter(): if "python" in proc.name(): print("name", proc.name()) script_path = sys.argv[0] proc_script_path = sys.argv[0] if len(proc.cmdline

How to create Sublime Text 3 build system which reads shebang

允我心安 提交于 2019-12-21 20:39:09
问题 How can I create a build system in Sublime Text 3 where "cmd" is replaced with a shebang if it exists? More specifically, is there a way to alter the Python build system to use the version of Python specified in the shebang, and use a default if no shebang is present? 回答1: Sublime build systems have an option named target which specifies a WindowCommand that is to be invoked to perform the build. By default this is the internal exec command. You can create your own command that would examine

shebang line not working in R script

泄露秘密 提交于 2019-12-21 03:45:26
问题 I have the following script #!/usr/bin/Rscript print ("shebang works") in a file called shebang.r. When I run it from command line using Rscript it works $ Rscript shebang.r but when I run it from the command line alone $ shebang.r It doesn't work. shebang.r command not found. If I type (based on other examples I've seen) $ ./shebang.r I get permission denied. Yes, Rscript is located in /usr/bin directory 回答1: Make the file executable. chmod 755 shebang.r 回答2: In addition to Sjoerd's answer..

Are there any javascript libraries for working with hashbang/shebang (#!) urls?

淺唱寂寞╮ 提交于 2019-12-20 10:44:21
问题 With all the negative press over Twitter and Gawker's use of hashbang urls I'm having a very hard time finding any examples/libraries for how to actually use them. I'd like to use hashbang urls in a javascript carousel on our website so we can link directly to a specific page of the carousel. Are there any good cross-browser libraries or examples (preferably non-jQuery, since we use Prototype) for both pushing new urls to the page location and for parsing the url on page load? 回答1: We've been

shebang not working to run bash scripts in linux

眉间皱痕 提交于 2019-12-20 07:40:57
问题 I can't seem to get bash scripts to turn into executable files via shebang. My code looks like #!/bin/bash echo "hello" where this is in a file called test.sh . I'm trying to get it to run with the command ./test.sh in the command line but i just receive the error of permission denied . When i change it to sudo ./test.sh I just get back that command not found . I can turn the file into an executable via the command the the command line: chmod +x test.sh and the code correctly outputs hello I

Invoking a script, which has an awk shebang, with parameters (vars)

老子叫甜甜 提交于 2019-12-19 05:03:43
问题 I have an awk script that I have defined thus: #!/usr/bin/env awk BEGIN { if (!len) len = 1; end = start + len } { for (i = start; i < end; i++) { print $1 } } I have saved it as columns and chmod +x 'd it. I want invoke it so that start and end are defined as it traverses over a file. I was thinking this should work: cat some_file | columns -v start=2 But it doesn't. Help! 回答1: Try using: #!/usr/bin/awk -f as an interpreter 回答2: env is the easiest way to handle this problem: #!/usr/bin/env

What's a shebang line for Scala that doesn't corrupt mimetype?

房东的猫 提交于 2019-12-19 02:52:09
问题 I've been using this, but it changes the mimetype to text/x-shellscript , which makes editors like Emacs treat my code like Shell scripts. #!/bin/sh exec scala "$0" "$@" !# 回答1: The bangshe (!#) might be the problem I commented out the !# and the following works in my environment: File: hello.sh #!/usr/bin/env scala val name = readLine("What is your name? ") println("Hello " + name + "!") Changed to executable permissions and then ran: chmod a+x hello.scala ./hello.scala 回答2: As I can test,