I want to have a cron job execute a python script using an already existing anaconda python environment called my_env. The only thing I can think to do is have the cron job run a script called my_script.bash which in turn activates the env and then runs the python script. Trying to execute this script from the command lines doesn’t
Tag: bash
Matplotlib plots aren’t shown when running file from bash terminal
Plots are normally shown when I run files from the ipython shell or from an ipython notebook, but they don’t show up when I run the file from a bash terminal — everything else works fine when is run from a bash terminal. Sample python script (trial.py): This is what I get (plot doesn’t show up): If I do before
Passing IPython variables as arguments to bash commands
How do I execute a bash command from Ipython/Jupyter notebook passing the value of a python variable as an argument like in this example: (obviously I want to grep for foo and not the literal string py_var) Answer General solution As suggested by Catbuilts, use {..}: Its behaviour is more predictable than $… E.g. if you want to concatenate another
git-p4 message and author encoding
today i am in the position to migrate some pretty old perforce repositories to git. While this is realy interesting there is one thing that caught my eye. All special characters in the commit messages and even the author names are not in the correct encoding. So i tried to investigate where the problem comes from. first of all the
Heroku: Run a Rails application with a Python script on the same instance
I have a Python script in the /app/bin directory of my Rails app that contains a requirements.txt file that includes all of the dependencies it relies on. How do I get it to run on the same Heroku instance that my Rails app currently runs on (my Rails app call the python script occasionally). Here’s what I’ve tried so far:
How to insert a python program into a bash script?
I have a small python program that parses a text file and writes the output to another file. Currently, I am writing a bash script to call this program several times, it looks something like: This works fine but I want to know if it is possible to have the python program inside the bash script file so when another
How to access Bash environment variable in Python using subprocess?
I can determine the width of the terminal in Python with a subprocess-handled query such as the following: How could I determine the Bash user name in a similar way? So, how could I see the value of ${USER} in Python using subprocess? Answer As Wooble and dano say, don’t use subprocess for this. Use os.getenv(“USER”) or os.environ[“USER”]. If you
piping from stdin to a python code in a bash script
I have a bash script, f, that contains python code. That python code reads from standard input. I want to be able to call my bash script as follows: In the example above, the python code will read from input.txt and will write to output.txt. I’m not sure how to do this. I know that if I wanted to just
Fast hash for strings
I have a set of ASCII strings, let’s say they are file paths. They could be both short and quite long. I’m looking for an algorithm that could calculate hash of such a strings and this hash will be also a string, but will have a fixed length, like youtube video ids: MD5 seems to be what I need, but
running multiple bash commands with subprocess
If I run echo a; echo b in bash the result will be that both commands are run. However if I use subprocess then the first command is run, printing out the whole of the rest of the line. The code below echos a; echo b instead of a b, how do I get it to run both commands? Answer