Giter VIP home page Giter VIP logo

pybin's Introduction

pybin

Latest PyPI version Supported Python versions License

When you install a package via pip install --user ..., any executables get placed in a special directory specifically for the intended user. Unfortunately, this location is most likely not included in your user's PATH variable. So for example if you did pip3 install --user hatch and then tried to learn more about your new tool by doing hatch --help, it would fail to be located. See: pypa/pip#3813

pybin solves this problem by providing a small CLI, and corresponding API, to locate your Python's user bin and optionally update the user PATH. It supports all major operating systems and does not require elevated privileges!

Fear not, this only modifies the user PATH; the system PATH is never touched nor even looked at!

Installation

pybin is distributed on PyPI as a universal wheel and is available on Linux/macOS and Windows and supports Python 2.6-2.7/3.3+ and PyPy.

$ pip install pybin

You may need sudo. Do NOT use --user!

Commands

Only 2!

pybin

$ pybin -h
Usage: pybin [OPTIONS] COMMAND [ARGS]...

  Shows the location of the bin directory and whether or not it is in the
  user PATH.

Options:
  -p, --pypath TEXT  An absolute path to a Python executable.
  --version          Show the version and exit.
  -h, --help         Show this message and exit.

Commands:
  put  Updates the user PATH

pybin put

$ pybin put -h
Usage: pybin put [OPTIONS]

  Updates the user PATH. The shell must be restarted for the update to take
  effect.

Options:
  -p, --pypath TEXT  An absolute path to a Python executable.
  -f, --force        Update PATH even if it appears to be correct.
  -h, --help         Show this message and exit.

API

>>> from pybin import in_path, locate, put_in_path
>>> in_path()
False
>>> locate()
'C:\\Users\\Ofek\\AppData\\Roaming\\Python\\Python36\\Scripts'
>>> success = put_in_path()

Manual modification

Use the location pybin shows in concert with this very comprehensive document Java provides: https://www.java.com/en/download/help/path.xml

License

pybin is distributed under the terms of both

at your option.

pybin's People

Contributors

ofek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

croydon cefn

pybin's Issues

PATH not being modified on macOS (High Sierra 10.13.5)

I'm trying to use hatch on macOS (High Sierra 10.13.5), and need to use pybin to update my patch to find the installed hatch script, but I can't get pybin to modify my path.

What am I doing wrong?

$ pip3 install --user hatch

$ hatch
-bash: hatch: command not found

$ sudo -H pip3 install pybin

$ pybin
The user bin directory `/Users/brendan/Library/Python/3.7/bin` is not in PATH.

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

$ pybin put
Success!

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

$ pybin put -f
Success!

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Great work - suggestions for tutorial and console output

This is a great little utility and I hope it is able to be maintained.

As you have probably noticed at pypa/pip#3813 there was a big issue around the message which should be shown to the user, regardless of what changes might be made.

Unfortunately I think pybin retains some of these issues of documentation and understandability in terms of the guidance and messages shown, but I think they may be easily fixed with your help.

Fix 1: Change the github README instructions so that users run python3 -m pybin

I suffer from the Debian curse of no .local/bin in my $PATH . Of course, this means that it is impossible to run pybin which is in .local/bin, which defeats its own purpose. Running the 'package main' of pybin using the -m option works regardless if .local/bin is on the path or not.

Fix 2: Provide an instruction showing how to fix the issue

I ran the following...

python3 -m pybin 
The user bin directory `/home/cefn/.local/bin` is not in PATH.

...but I was disappointed that it didn't offer a fix. It should instead read as follows.

python3 -m pybin 
The user bin directory `/home/cefn/.local/bin` is not in PATH.
Run type the following line and press enter to fix your path...
python3 -m pybin put

Alternatively you could have pybin by default offer an interactive prompt to fix a non-existent path, with flags to override interactive (do nothing) or force (change the path non-interactively).

Success!

I ran...

python3 -m pybin put
Success!

..and it had successfully added the path line to the end of my .bashrc. Brilliant! This will be very useful for me as an educator working with learners who may be following my instructions to install python3 at home, as part of the VGKits Vanguard project.

Thanks for your intervention. It could save a world of pain for lots of people.

Pybin should prefix added path line with a newline

I found that in a default skeleton user directory in Elementary 5 (based on Ubuntu bionic), there is no final newline in the .bashrc file, which instead finishes with the word 'esac' which is the end of a case statement.

Pybin's default editing behaviour therefore causes this error...

bash: /home/cefn/.bashrc: line 171: syntax error near unexpected token `PATH="/home/cefn/.local/bin:$PATH"'
bash: /home/cefn/.bashrc: line 171: `esacexport PATH="/home/cefn/.local/bin:$PATH"'

This is easily resolved by putting a newline after the word 'esac' but it would be better if pybin preceded the edit performed by its 'put' behaviour with a newline to be sure this doesn't happen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.