Installing s3cmd on MacOS High Sierra with pip

1

I have installed s3cmd with pip on MacOS High Sierra, which has successfully installed.

sudo pip install --user s3cmd
The directory '/Users/crmpicco/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/crmpicco/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting s3cmd
  Downloading https://files.pythonhosted.org/packages/c0/55/ff0ba1d725d3b43c1b116907b4891da0a3b3193e7fa23f75d9fff7a6431e/s3cmd-2.0.1.tar.gz (121kB)
    100% |████████████████████████████████| 122kB 85kB/s 
Requirement already satisfied: python-dateutil in /Library/Python/2.7/site-packages (from s3cmd) (2.6.1)
Requirement already satisfied: python-magic in /Library/Python/2.7/site-packages (from s3cmd) (0.4.15)
Requirement already satisfied: six>=1.5 in /Library/Python/2.7/site-packages (from python-dateutil->s3cmd) (1.11.0)
Installing collected packages: s3cmd
  Running setup.py install for s3cmd ... done
Successfully installed s3cmd-2.0.1

However, I am unable to run it.

s3cmd --configure
-bash: s3cmd: command not found

If I do a search for it, it is showing in the /Homebrew directory:

locate s3cmd
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/s3cmd.rb

What am I missing to run this?

crmpicco

Posted 2018-05-17T08:32:30.470

Reputation: 305

Answers

1

  1. Don't do sudo pip install --user. This corrupts your user dir - you are installing as root to your user dir, this is a source for potential problems. Reinstall with

    $ sudo pip uninstall -y s3cmd
    $ pip install s3cmd --user
    

    1.1. Since you've already installed as root, it is likely that pip's cache dirs or files were chown'ed to root - should there be any complaints, fix the ownership with

    $ sudo chown -R crmpicco:staff /Users/crmpicco/
    

    Try running s3cmd -h or s3cmd --version now, if it works, you're already done. If not, continue reading.

  2. Now that you have properly installed the package, list files installed:

    $ pip show -f s3cmd
    

    Find the path to the script, it will be smth like ../../bin/s3cmd, given relative to the Location dir. You need to construct the full bin path, it should be smth like /Users/crmpicco/Library/Python/X.X/bin.

  3. Append the constructed bin path to PATH and try calling the command:

    $ PATH=$PATH:/full/path/to/bin s3cmd --version
    
  4. If the above command succeeds, append the bin path to PATH permanently: open ~/.bash_profile and add the lines

    PATH="/full/path/to/bin:${PATH}"
    export PATH
    

    Save the file and either restart the terminal or run source ~/.bash_profile to apply the changes. Now you should be able to call s3cmd anytime.

hoefling

Posted 2018-05-17T08:32:30.470

Reputation: 478

This is great, thanks. I'm all good up until number 4. I already have a PATH environment variable set like this export PATH="/usr/local/sbin:$PATH". How should I add the full Python bin path to the existing PATH variable as I don't want to clobber the existing variable? – crmpicco – 2018-05-24T01:42:01.473

1You won't clobber it if you add the lines from the answer. /usr/local/sbin will still be in PATH, you can check that anytime: enter echo $PATH in terminal to print the variable. You can of course combine two lines into one export PATH="/python/bin:/usr/local/sbin:${PATH}", but it will have the same effect in the end. – hoefling – 2018-05-24T08:05:42.610

1Great, thanks for your help @hoefling. You answer was well explained. I ended up adding /Users/crmpicco/Library/Python/2.7/bin to /etc/paths. – crmpicco – 2018-05-30T06:45:57.813