2

Normally when I had a module I want to use for a specific project I just put the module in the project folder and imported it from the script, where it was needed. But I created some modules, which are helpful in total, so I want them to be accessible from everywhere. (like modules of the standard library of python)

Example Module (pcinput.py):

def getFloat(prompt='Enter your Float: '):
    while True:
        try:
            num = float(input(prompt))
        except ValueError:
            print('Float expected -- please try again')
            continue
    return num

Properties:

OS: Ubuntu 16.04

Python Version: 3.5.2

Rahul K P
  • 15,740
  • 4
  • 35
  • 52
Uuser
  • 49
  • 3
  • So put `pcinput.py` in `sys.path`? More on the subject [here](https://docs.python.org/3/glossary.html#term-import-path) – Torxed Oct 03 '16 at 12:13
  • 1
    Use `distutils` from the standard library to create a package - it will install them into the `site-packages` directory. But you will need user `root` for that. – cdarke Oct 03 '16 at 12:16
  • 1
    Use package? https://packaging.python.org/distributing/ – Anthony Kong Oct 03 '16 at 12:16
  • @cdarke distutils/setuptools distributions can be installed in several ways, not all of them require root privileges. – Stop harming Monica Oct 03 '16 at 12:24
  • @Goyo: I meant to install into `site-packages`, the question said " I want them to be accessible from everywhere". – cdarke Oct 03 '16 at 18:53

0 Answers0