0

(I'm not sure exactly what SE site my question belongs, I hesitated between stackoverflow, serverfault and superuser. Feel free to give suggestions about this in the comments.)

Here is my problem:

I have two users on my linux computer, bli and pquarato. bli installed python3.6 locally (compiling from source with ./configure --prefix=${HOME}). The binary is installed in /home/bli/bin, pip3.6 installs things in /home/bli/.local/lib/python3.6/site-packages. For instance, numpy is installed there:

(bli) $ pip3.6 install numpy
Requirement already satisfied: numpy in /home/bli/.local/lib/python3.6/site-packages

I want pquarato to be able to use bli's python installation. bli did chmod -R a+rx on /home/bli/bin and /home/bli/.local.

pquarato can use bli's python3.6 binary, but it is not able to import modules installed with pip3.6:

(pquarato) $ /home/bli/bin/python3.6 -c 'import numpy'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'

The above works without errors for bli.

What else should I do?


Note: I actually first ran into a problem when trying to get pquarato to use programs such as ipython3:

(pquarato) $ /home/bli/.local/bin/ipython3 
Traceback (most recent call last):
  File "/home/bli/.local/bin/ipython3", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/home/bli/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3017, in <module>
    @_call_aside
  File "/home/bli/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3003, in _call_aside
    f(*args, **kwargs)
  File "/home/bli/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3030, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/bli/lib/python3.6/site-packages/pkg_resources/__init__.py", line 659, in _build_master
    ws.require(__requires__)
  File "/home/bli/lib/python3.6/site-packages/pkg_resources/__init__.py", line 967, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/bli/lib/python3.6/site-packages/pkg_resources/__init__.py", line 853, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'ipython==6.2.1' distribution was not found and is required by the application

I hope that the same solution will solve both the ModuleNotFoundError and the above DistributionNotFound issue.

  • Is the use of sudo not an option? This way pquarato can run Python as if he/she was bli. – Raman Sailopal Apr 4 '18 at 12:09
  • @RamanSailopal Good suggestion, but I would prefer a safer solution. – bli Apr 4 '18 at 12:13
  • @Christopher In some situations, it may not be convenient to ask root every time one needs to install a python package. – bli Apr 4 '18 at 14:34
0

I added the following to /home/pquarato/.bashrc:

export PYTHONPATH="/home/bli/.local/lib/python3.6/site-packages"

This seems to solve both issues (ModuleNotFoundError and DistributionNotFound).

The .bashrc file needs to be sourced before this takes effect.

This probably needs to be adapted depending on the shell that the user uses.


Edit

Setting PYTHONPATH doesn't seem to work with local packages that were installed as *.egg-link using pip3.6 install -e. In such cases, there is still a ModuleNotFoundError.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.