How do I access packages installed by `pip --user`?

前端 未结 3 1105
我在风中等你
我在风中等你 2020-12-14 08:16

I realized I had an outdated numpy version:

$ python
Python 2.7.10 (default, Oct 23 2015, 18:05:06)
[GCC 4.2.1 Compa         


        
相关标签:
3条回答
  • 2020-12-14 08:57

    @Claudiu's solutions works pretty well, a little bit more cleaner would be:

    python3 -m site --user-base
    

    e.g. something like this in your .profile:

    PATH="$(python3 -m site --user-base)/bin:${PATH}"
    
    0 讨论(0)
  • 2020-12-14 09:00

    As per the Python docs, this is installing using the "user scheme":

    Files will be installed into subdirectories of site.USER_BASE (written as userbase hereafter).

    You can see your USER_BASE value like this:

    $ python -c "import site; print(site.USER_BASE)"
    /Users/csaftoiu/Library/Python/2.7
    

    I found that on my machine, this was on sys.path, but it came after the global install directories.

    I solved it by adding this to my ~/.bash_profile:

    # add user base to python path
    export PYTHONPATH=$(python -c "import site, os; print(os.path.join(site.USER_BASE, 'lib', 'python', 'site-packages'))"):$PYTHONPATH
    

    Now the latest version is indeed loaded:

    $ python
    Python 2.7.10 (default, Oct 23 2015, 18:05:06)
    [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy
    >>> numpy
    <module 'numpy' from '/Users/csaftoiu/Library/Python/2.7/lib/python/site-packages/numpy/__init__.pyc'>
    >>> numpy.version.full_version
    '1.11.1'
    >>>
    
    0 讨论(0)
  • 2020-12-14 09:18

    I installed packages with sudo pip install --user option and I had to do sudo python to get it working.

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

    With sudo:

    vishnu$ sudo python
    Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import rasa_core
    >>> 
    

    Without sudo:

    vishnu$ python
    Python 2.7.10 (default, Jul 15 2017, 17:16:57) 
    [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import rasa_core
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named rasa_core
    

    PS: I am running these on Mac OS High Sierra and my issue was with rasa_core and dependent packages.

    0 讨论(0)
提交回复
热议问题