Setting iPython default profile - ipython

Right after installing IPython, I created a default profile with:
$ ipython profile create
Then, I created another one, this time I gave it the name testing:
$ ipython profile create testing
I have customized this testing profile (the prompt, and autoreload extension, etc) to my liking, and now I would like it to be my default profile, so it's started when I type:
$ ipython
I know that I can start it with:
$ ipython --profile=testing
But that is a lot of typing.
I have already tried editing the file ipython_config.py in the profile_default folder, line 89:
# The IPython profile to use.
c.TerminalIPythonApp.profile = 'testing'
But it's not working. Any ideas why? Is it broken?
EDIT: Since I have to use different profiles for periods of time of weeks or fortnights, I'm looking for a way of selecting a default profile for those periods of time. It would be awesome achieving that from IPython itself, in the meantime, a very convenient workaround is adding an alias in the bash configuration(as pointed out by cel in one of the comments):
alias ipython='ipython --profile=testing'

Take a backup of profile_default and then rename profile_testing to profile_default.
Or you can copy the contents of profile_testing to profile_default.

Related

Broke my terminal with a bad PATH [duplicate]

This question already has an answer here:
Wrong path set and now .bashrc throws errors [duplicate]
(1 answer)
Closed 6 years ago.
I put an invalid path into my bashrc and now my terminal doesn't work. I've deleted my bash_profile as well as my bashrc and I still can't get it to work.
Every command I use in terminal gives me the error:
sh: parse_git_branch: command not found
This was something I had in my bash_profile for git autocompletion. The problem is once I've deleted the files using /bin/rm <file>, I can't apply my changes with source ~/.bash_profile because it's giving me errors. I've looked at this question, and this question, but I still am having no luck.
How can I fix my command line after breaking things like this?
You can export a correct PATH in your current session using a command similar to :
export PATH=/usr/local/bin:/usr/bin:/bin
After using this, you should be able to source your bashrc.
You can always change your path right on the command line for the rest of the current shell session: PATH="/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin:"
Exporting the PATH won't solve your problem. It will only export the value of PATH to child shells/processes. This only achieves the same thing as resetting/changing the PATH variable from the command-line (as shown above), because your scope is limited to the current shell process (and its children) while you are working within that shell environment (working from the command-line). If you open a new terminal (start a new login shell, which is a parent process), bash will still be trying to read from the resource files (.bash_profile and .bashrc), which no longer exist.
So, we need to be able to widen our scope and tell bash that we want to make changes for all future bashes (shell processes--new shells, shells within shells, etc.), and the way that is done is by writing those statements in the resource files.
Once you set your PATH there, every shell session will spawn with those resources (all the aliases, commands, variables, and functions stored in those files), loaded, regardless of whether you export it or not, since each shell process will always consult those files before it does anything else (so they effectively pre-emptively import what you are trying to export to them).
bash is like any other script or program. You took away all its inputs and pointers and shortcuts, and now its just been made pretty dumb, so you've got to be explicit with everything you do till you can teach it where to look for stuff (give it a PATH to search) and shorten your conversations with it.
If you don't have a backup of your .bash_profile, here's one that you can use:
# This loads in the configuration in .bashrc
# Put all configuration in there!
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
And here's a .bashrc that can get you started:
export PATH="/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin:"

Mac OS X 10.11 - Add Postgres to $PATH Unsuccessful

I am trying to install Postgres in order to use Heroku.
I am following the instructions in the Heroku tutorial, and after Postgres installation (which was successful), it says to configure my .bash_profile to allow for Postgres command line functionality.
I am following the instructions here, but I am unable to successfully add this line:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
That folder does in fact contain "psql" on my computer, so it should work. Here is my current .bash_profile:
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# The next line updates PATH for the Google Cloud SDK.
source '/Users/user/google-cloud-sdk/path.bash.inc'
# The next line enables shell command completion for gcloud.
source '/Users/user/google-cloud-sdk/completion.bash.inc'
I tried to add the Postgres line to the end of that file, but it is not working. After searching online, there does not seem to be consensus on how to add PATHs to .bash_profile. I have tried many versions listed, but none have worked.
Please let me know if I'm doing this incorrectly!
Add this line to the end of your .bash_profile:
export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
This makes the search of a binary to look in that location "BEFORE the rest of the PATH"
Kill all instances of terminal and open it again, then it should work.
Try which xxx where xxx is the name of some binary inside /Applications/Postgres.app/Contents/Versions/latest/bin and check if it's returning that location.
Tell me if it works.

Putting default text into a new Jupyter notebook

Is there a way to open a new Jupyter notebook from a template? (which would not itself be modified)
I would expect something like this perhaps:
jupyter --template <template-filename>
(re-using the existing jupyter-notebook server session if there is one already)
But I don't seem to see how to do it (as of Jupyter 4.0.6)
I admit it's a rather hacky workaround, but just in case there is no implemented solution: You could make an alias in your .bashrc like this:
alias newnb='cp -i ~/templates/jupyter.ipynb new_notebook.ipynb && juypter notebook'
Then, the command newnb in your terminal copies the template file to your current directory and invokes the jupyter notebook session on this directory, where you could open new_notebook.ipynb with the given content.

set default working directory for ipython console (terminal)

ipython notebook has setting for default working directory
c.FileNotebookManager.notebook_dir = '/path/to/my/desired/dir'
is there analogous setting for ipython console (terminal) ? I have tried adjusting following configuration parameter:
c.TerminalInteractiveShell.ipython_dir = '/path/to/my/desired/dir'
but this seems to have no effect. There is also no comment as to what this parameter is supposed to effect.
How can I configure ipython so that my working directory upon start will be /path/to/my/desired/dir, irrespective from where I started ipython ?
From your home directory, go to .ipython, then your profile directory (probably profile_default), then startup. In there, create a new file with the extension .ipy, containing the lines:
import os
os.chdir('/path/to/my/desired/dir')
As pointed out by crowie in the comments, the .ipy extension also enables you to use IPython "magic" commands, so you could instead say:
%cd /path/to/my/desired/dir

How can I modify command line in Ubuntu 10.04?

I am using a vpn service from certain server. I was given with a root account, and when I connect with a root account, the command line looks like below.
root#xa9g82:/etc/#
Then I used useradd to add an account called 'temp'
When I connected to the server with temp, then the command line only has a single character.
$
The user information is not shown, neither the path. Also, note that, in root's command line I can use tab to automatically complete the filename, however 'temp's command line inserts tab space, when I press tab. It is very inconvenient.
I am using Ubuntu 10.04. How can I resolve this issue?
I usually edit ~/.bashrc. Being root, you might want to change the system-wide preferences, at /etc/bash.bashrc. Personally, I changed some lines in ~/.bashrc to look like:-
# If this is an xterm set the title to user#host:dir
case "$TERM" in
xterm*|rxvt*)
## PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u#\h: \w\a\]$PS1" # default
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\h: \W\a\]$PS1" # How I like it
;;
*)
;;
esac
use prompt to set the prompt.... (man prompt...)
it depends on what shell you run each one has it's own tricks, but you can make it looks as you wish.
BASH
TCSH
It is likely that the default shell for root is set to /bin/sh, which does not provide many of the features that you may used to if you use a shell like bash. To check if this is the case, run the following command:
cat /etc/passwd | grep ^root
The last component of the line that this command outputs will be your shell (which, as stated previously, I'm guessing is /bin/sh). If this is not the shell you want (it probably isn't), then edit /etc/passwd (using nano or whatever editor you're most comfortable with) and change your shell to something more palatable, like /bin/bash. After doing this, you'll need to log out and then log back in.