3

I installed python 3 and pip3 into in Windows System for Linux shell that uses Ubuntu, but it appears I have to find and specify site-packages or $HOME/.local/bin directory manually if I want to run any python package executables.

The package I want to use is cheat, but the problem is the same for any other package.

My chain of commands was:

  1. install WSL - Ubuntu 18.04
  2. sudo apt-get update (because sudo apt-get install pip3 will not work on fresh installation)
  3. sudo apt-get -y install python3-pip (installs python too) - edited
  4. sudo pip3 install cheat
  5. cheat not recognised as a command, while python3 runs fine from /usr/bin/python3
  6. find locations where cheat is found, they are:

    $HOME/.local/bin/cheat 
    $HOME/.local/lib/python3.6/site-packages/cheat
    
  7. When I add any of these directories to path, I'm able to run python executables, cheat ls works.

Is there something I can change in the installation process so that I mustn't search for directories and add them manually to path?

Evgeny
  • 141
  • 6
  • 1
    I don't understand: `~/.local/bin` is where pip usually installs executables for user-installation. You only need to know that once, there's no need to search for the location again and again. – muru Sep 27 '18 at 21:59
  • @muru - I'm saying that on a bare linux installation a user would have to search for `~/.local/bin` to find out where the executable is, if he has no prior knowledge of pip behaviour. On Windows executables work right after pip install, no searching needed. – Evgeny Sep 28 '18 at 05:52
  • @muru - also not clear why `sudo pip3 install cheat` still installs to a user home directory. – Evgeny Sep 28 '18 at 05:53
  • all the more reason to be aware of the behavior of tools that download programs from the internet. As for sudo pip, I assumed you ran one command and pasted another here, because sudo pip installs binaries to `/usr/local/bin`, which is in PATH. – muru Sep 28 '18 at 06:05
  • @muru - do you care to post your last comment as an answer? This is really the case after I repeted my steps: `sudo` does install at `/usr/local/bin/cheat` and local directories installation emerges when doing pip with no `sudo`. – Evgeny Sep 29 '18 at 06:32
  • I know with some modules you can do `python -m modulename`. That'll search for modules in their respective paths. But depends on how module is built. – Sergiy Kolodyazhnyy Sep 29 '18 at 06:40
  • @ Sergiy Kolodyazhnyy `python -m` is a good idea, I sometimes invoke `pytest` like this to persist a start folder, but for cheat specifically it is doesnt work. – Evgeny Sep 29 '18 at 20:38

1 Answers1

1

@muru provided proper diagnostics: the issue with local directories arises only when running pip3 install cheat.

When running sudo pip3 install cheat the package executable installs to /usr/local/bin/ which is on path.

For the rest of the question "Why did my local version of python package install to a directory which is not in path", the overall answer is close to "You have to know your system and folder structure", which equates to "Put ~/.local/bin/on path.

So reiterating to conclude - if you are installing a package with pip and you are not in sudo mode, you have to add ~/.local/bin/ to path to make package executable run.

Evgeny
  • 141
  • 6