2

I installed python 3 and pip into in Windows System for Linux shell, but it appears I have to find and specify site-packages directory manually if I want to run any python package executables. The packages I wanted to use were cheat and awscli, but the problem is the same for any package.

My chain of commands was:

  • install WSL - Ubuntu 18.04
  • sudo apt-get update (because sudo apt-get install pip3 will not work on fresh installation)
  • sudo apt-get install pip3 (installs python too)
  • sudo pip3 install cheat
  • cheat not recognised as a command, while python3 runs fine from /usr/bin/python3
  • realise $HOME/.local/lib/python3.6/site-packages must be on path
  • in ~/.profile add $HOME/.local/lib/python3.6/site-packages to path with export PATH="$HOME/.local/lib/python3.6/site-packages:PATH"
  • restart ~/.profile

I there something I can change in the installation process so that I mustn't search for site-packages directory and add it to path manually?

UPDATE: proper call executed for pip was sudo pip3 install cheat. there is no plain pip on the system. calling pip results in error Command 'pip' not found.

  • Any comment accompanying a downvote will be highly appreciated – Evgeny Sep 27 '18 at 9:59
  • 1
    First of all, never use sudo pip install. By that, you save yourself a lot of future errors. Use pip install --user instead. Do it right now: got through pip3 list output, try to find packages you already installed (plus their dependencies), uninstall and reinstall them as user. By doing that, you will immediately notice the commands to become available because of the PATH changes you made. – hoefling Oct 2 '18 at 11:34
  • If you, however, like to live on the edge and insist on sudo pip installing, adjust the PATH correctly: check out the output of pip3 show cheat | grep Location, two segments up and descend into bin and add that directory to PATH. – hoefling Oct 2 '18 at 11:38
  • @hoefling - exactly two things I was missing in the workflow! Do you care to put these comments as an answer, so that I can accept it? Installing as a user is indeed the missing step! – Evgeny Oct 2 '18 at 13:46
  • I have also noticed you're adding the wrong dir to PATH; suggested a fix in the answer. – hoefling Oct 2 '18 at 21:50
2
  1. as suggested in the comments: don't use sudo pip install as you will get conflicts with the system package manager sooner or later. Always install python packages via pip install --user.
  2. $HOME/.local/lib/python3.6/site-packages shouldn't be on PATH, it's the directory containing python modules (python source code files), but no executables. You can check the path for user-installed executables with:

    $ python3 -m site --user-base | xargs -I {} echo {}/bin
    

    Most probably it's the $HOME/.local/bin. Add this one to PATH instead of site-packages. In your .profile/.bashrc/.bash_profile (whatever your OS specifies):

    PATH="$HOME/.local/bin:$PATH"
    export PATH
    

    Notice the $PATH instead of PATH in the path appending command. Now restart the terminal (or source the profile file) and check whether the installed executables are available:

    $ which eb
    $ eb --help
    

    etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.