Where did I go wrong in virtualenv installation on OSX? - macos

I followed the instructions carefully at http://jamie.curle.io/blog/installing-pip-virtualenv-and-virtualenvwrapper-on-os-x/
Restarted my terminal and typed mkvirtualenv, got a command not found
looked in /usr/local/bin and ls shows me:
brew powerpc-apple-darwin8-gfortran-4.2
charm tclsh8.5
django-admin.py tclsh8.6
django-admin.pyc virtualenv
gfortran-4.2 virtualenv-2.7
gfortran-uninstall virtualenv-clone
i686-apple-darwin8-gfortran-4.2 virtualenvwrapper.sh
node virtualenvwrapper_lazy.sh
pip wish8.5
pip2 wish8.6
So I know it's in the correct directory. I don't understand where I could have screwed up.

The linked article recommends adding the line source /usr/local/bin/virtualenvwrapper.sh to bash login profile file ~/.bash_login.
However,
~/.bash_login is rarely used.
it is NOT read if the much more common (on OS X) ~/.bash_profile also exists.
Thus,
Check if you have a ~/.bash_profile file
and, if so, add the line source /usr/local/bin/virtualenvwrapper.sh there.
My recommendation is to never use ~/.bash_login. If you find other content, there, also add it to ~/.bash_profile, and delete ~/.bash_login.
Alternatively, if you're looking for cross-platform compatibility, put all definitions in ~/.bashrc instead, and add only [[ -e ~/.bashrc ]] && . ~/.bashrc to ~/.bash_profile.

Related

$PATH error every time Terminal is Opened

I had installed Postgres.app before and after I uninstalled via App Cleaner now every time I open terminal this error appears in the first line I should mention that a followed what documentation for uninstalling the Postgres on their website but it doesn't work for me.
Warning: $PATH entry "/Applications/Postgres.app/Contents/Versions/9.6/bin" is not valid (No such file or directory)
.bash_profile:
# source ~/.profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="/usr/local/opt/node#6/bin:$PATH"
how can I get rid of this annoying warning?
Thanks.
You should look at all bash initialization files. There may be many, depending on your distro. There's a good list on tldp:
/etc/bash.bashrc
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
Consider that some of these files may also include all files in some directory. For example on most instances /etc/profile will run every .sh file in /etc/profile.d/, this may include a paths file called /etc/profile.d/extrapaths.sh.
EDIT:
After checking the documentation for PostgresApp (1, 2), and this issue I found that it uses a file called /etc/paths.d/postgresapp. Be sure to check it.
If you'd like to remove the paths, it states that you should run the following command:
sudo rm /etc/paths.d/postgresapp

-bash: vim: command not found

I have been trying to install something in my bash_profile, which looked like this:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
I was trying to add the Path to my pg_config file: /Applications/Postgres.app/Contents/Versions/9.6/bin
So my bash_profile looked like:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
When I tried to source the file i got:
-bash: /usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:: No such file or directory
When I try to open the bash_profile I now get:
-bash: vim: command not found
What have I done wrong?
Additional info
I have installed Python, PGAdmin4 and Django via Homebrew
I have downloaded Postgress.app also and was trying to install psycopg2, when it told me I had no pg_config. So I was trying to add the path to my bash_profile. Which I think is the right thing to do
#melpomene and #Jdamian I think were right here. I had trouble trying to then find and open my bash_profile as I couldn't use the terminal to run:
defaults write com.apple.finder AppleShowAllFiles YES
Thankfully this answer helped though: https://apple.stackexchange.com/a/186378/70982
I navigated in finder to my ~/ folder and and ran
⌘ CMD+⇧ SHIFT+.
Opened in sublime and My path had was written as this:
export PATH=/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:
$PATH
So I removed the carriage return so it all fits on one line and that seemed to help. I can now open Vim

"reload ~/.bash_profile"error by installing virtualenvwrapper

The virtualenvwrapper official documents ask me to add three lines to ~/.bash_profile, but I add three wrong lines to there, and then, there is an error looks like below after I reloaded by commandsource ~/.bash_profile
/Users/donald/.bash_profile:1: bad assignment
Can anyone tell me how to do and why? and if someone can teach me how to install virtualenvwrapper? I have spent a whole night working on this and fail.
The three wrong command lines are:
export WORKON_HOME=~/Envs
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
It's just a simple question, I found the answer later.
After you add wrong command lines to .bash_profile , you can use the command lines below to get a easy-editing window
touch ~/.bash_profile
open -e ~/.bash_profile
then you will know how to do.
And...
If you are confused with installing virtualenvwrapper, have a look on this:
virtualenvwrapper.sh is not in /usr/local/bin, you can use the command line below to find where is it.
which virtualenvwrapper.sh
After that, you can copy the virtualenvwrapper.sh to /usr/local/bin or change the path after source command in the .bash_profile.
Remember to reload the .bash_profile with the command line below everytime you use virtualenvwrapper.
source ~/.bash_profile
Thanks~!

Terminal: Where is the shell start-up file?

I'm following a tutorial called Starting a Django 1.4 Project the Right Way, which gives directions on how to use virtualenv and virtualenvwrapper, among other things.
There's a section that reads:
If you're using pip to install packages (and I can't see why you wouldn't), you can get both virtualenv and virtualenvwrapper by simply installing the latter.
$ pip install virtualenvwrapper
After it's installed, add the following lines to your shell's start-up file (.zshrc, .bashrc, .profile, etc).
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/directory-you-do-development-in
source /usr/local/bin/virtualenvwrapper.sh
Reload your start up file (e.g. source .zshrc) and you're ready to go.
I am running Mac OSX, and don't know my way around the Terminal too well. What exactly does the author mean by shell's start-up file (.zshrc, .bashrc, .profile, etc)? Where do I find this file, so that I can add those three lines?
Also, what does he mean by reload your start up file (e.g. source .zshrc)?
I would appreciate a detailed response, specific to OSX.
You're probably using bash so just add these 3 lines to ~/.bash_profile:
$ cat >> ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/directory-you-do-development-in
source /usr/local/bin/virtualenvwrapper.sh
^D
where ^D means you type Control+D (EOF).
Then either close your terminal window and open a new one, or you can "reload" your .bash_profile like this:
$ source ~/.bash_profile
If you use bash, it usually means ~/.bash_profile.
In Terminal and iTerm new shells are login shells by default, so ~/.bashrc is not read at all. If instructions written for some other platform tell you to add something to .bashrc, you often have to add it to .bash_profile instead.
If both ~/.profile and ~/.bash_profile exist, only .bash_profile is read. .profile is also read by other shells, but many of the things you'd add to .bash_profile wouldn't work with them.
From /usr/share/doc/bash/bash.html:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
[...]
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.
I have Anaconda install, so I add these 3 lines to ~/.bash_profile
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Documents/Python
source /Users/Username/anaconda3/bin/virtualenvwrapper.sh
and then reload profile by:
$ source ~/.bash_profile
I use an approach that I think is easy to maintain.
It also works well if you sometimes use Ubuntu systems, however I will be sure to address the OP's OSX requirement in my answer.
Create a .aliases file with your alias(es) in your home directory, e.g. ~/.aliases
Execute this file from your .bashrc file (this is executed each time for a new shell process) with source ~/.aliases. This is all you would actually need to do for Ubuntu btw.
On OSX call .bashrc from your ~/.profile file, i.e. have ~/.bash_profile contain: source ~/.bashrc

How to properly setup my git $PATH on my mac (I did, but need to understand how it really works)?

I installed GIT from the site on my mac, but git --version gave me the old installation (I guess xcode installation). So I solved doing this:
create a ~/.bash_profile file
write:
export PATH=/usr/local/bin:$PATH
restart the terminal
Though, I think there's something in my configuration I could better setup.
My current echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
So IT WORKS, but it's quite a mess, since I've got 2
/usr/local/bin AND an /usr/local/git/bin
Also, I cannot understand WHY now it works, since /usr/local/bin only contains bbedit commands:
bbdiff
bbedit
bbfind
I do not know very well all the path-config files and the real order they are read. I only know a few unix commands..
My current files in ~/ are:
~/.profile:
if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi
~/bashrc:
. ~/bin/dotfiles/bashrc
then in . ~/bin/dotfiles/bashrc
. ~/bin/dotfiles/bash/env
. ~/bin/dotfiles/bash/config
. ~/bin/dotfiles/bash/aliases
and in . ~/bin/dotfiles/bash/env:
export PATH=/usr/local/bin:/opt/local/bin:/opt/local/sbin:$PATH
. ~/bin/dotfiles/bash/config is just empty
and . ~/bin/dotfiles/bash/aliases contains some alias commad.
Anyway, it SHOULD have read ~/bin/dotfiles/bash/env, but it doesn't. Or it reads it only after /etc/paths
~/.bash_profile is read first instead.
My current /etc/paths content:
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
Can anyone explain me the these mechanics? :P Or Maybe I should post this question to some Unix group?
When you type any command on a *NIX shell, the shell tries to resolve that command using the $PATH. Say your path is /usr/bin:/usr/local/bin, then this happens:
$ foo
- Does /usr/bin/foo exist? No.
- Does /usr/local/bin/foo exist? No.
- Does foo exist in the current working directory?
In other words, it looks at each $PATH element in turn and tries to find the executable you asked for there. This is the reason the typical configure-make-make install procedure starts with a ./configure, to make explicit that you want to run the configure executable in the current directory, not some system-wide command.
To figure out which foo it's actually choosing in the end, run:
$ which foo
You can run any command explicitly by providing its full path:
$ /usr/local/bin/foo # overrides /usr/bin/foo, should it exist
The export PATH=...:$PATH directive in your initialization scripts is simply prepending certain paths to your path, allowing you to override the precedence in which order commands are resolved. It's not ideal that /usr/local/bin is in there twice, but it's not really a problem either. You should take care not to let your path grow too long, since that may result in a lot of lookups for every command and may screw with your head, too.
See this for a comprehensive walkthrough of bash config files' loading order.

Resources