How do I make python modules available to all users?

21,799

I strongly recommend avoid using python-pip on production context. Modules installed that way aren't updated during system updates which may lead to vulnerabilities that never get patched ....

Nevertheless, pip, by default, install the module only in calling user's $HOME. For pip to install "system-wide", use the --system switch.

For more details, see pip install --help output

EDIT --system looks to be a debian specific option.

binarym@avalon:/tmp/python-pip-18.1/debian/patches$ grep -- '--system' *
set_user_default.patch:+:ref:`--system <install_--system>` option to ``pip install``.
set_user_default.patch:+            '--system',

Thanks @co2f2e for your comment.

Share:
21,799

Related videos on Youtube

C McNorgan
Author by

C McNorgan

As a cognitive neuroscientist with a CompSci background, I'm a regular MATLAB user. I was a internet application developer in a former life (PHP; ASP, before dot-net), but my knowledge in that domain is now pretty stale.

Updated on September 18, 2022

Comments

  • C McNorgan
    C McNorgan over 1 year

    I work in a multi-user setting and am relatively new to Python. The machines in question run Ubuntu 16.04, and we are using Python 2.7. I personally have installed several additional modules, such as tensorflow, keras, and some other related modules and I believe I used the pip installer (pip 18.0 from /usr/local/lib/python2.7/) to install these (sudo pip install X).

    I've been successfully running python scripts for months using all of these modules but another user has been unable to run any python code that uses any of the modules that I've installed. Even a 1-line script that exists only to import a module such as:

    import tensorflow
    

    fails to run, generating an ImportError (I'll only paste the last couple of lines):

    File "/usr/local/lib/python2.7/dist- 
     packages/tensorflow/python/ops/variable_scope.py", line 24, in <module>
    import enum  # pylint: disable=g-bad-import-order
    ImportError: No module named enum
    

    What did I do wrong that's making these modules invisible to other users, and how can I fix it?

  • ox12
    ox12 over 4 years
    where did you get that option --system ?
  • binarym
    binarym over 4 years
    As mentionned in my answer, pip install --help
  • ox12
    ox12 over 4 years
    pip.pypa.io/en/stable/reference/pip_install/… please go through the documentation . No such option is available
  • binarym
    binarym over 4 years
    You're right... Looks like my Debian implements a pip option that doesn't exist in uptstream. Maybe a Debian patch ?
  • ox12
    ox12 over 4 years
    There never been such an option @binarym
  • binarym
    binarym over 4 years
    @co2f2e see my edit. I fetched the source package for python-pip on Debian. The --system is implemented by a patch that has probably been added by Debian maintainer.
  • ox12
    ox12 over 4 years
    this is more of a hacky way to do it
  • binarym
    binarym over 4 years
    Seeing the number of response in this question ... looks like it is the "only" way to do it ? ;-(
  • ox12
    ox12 over 4 years
    Negative, if you install any module like pip install dependency, without specifying a user it will available for all users
  • Vasin Yuriy
    Vasin Yuriy about 4 years
    no such option: --system
  • Vasin Yuriy
    Vasin Yuriy about 4 years
    no such option: --system
  • binarym
    binarym about 4 years
    Did you read comments ?
  • flaschbier
    flaschbier almost 3 years
    "avoid using python-pip on production context" – ok. But what to use then to install dependencies?