0

So i just freshly installed ubuntu 18.04 which comes with python3.6 out of the box. then i installed pip

sudo apt update
sudo apt install python3-pip

after that i installed pandas using

pip3 install pandas

which got stored at

/home/anubhav/.local/lib/python3.6/site-packages

which i assume is the expected path where it should install. Now i created a system user

sudo adduser --system ggc_user

and then i imported pandas using:

sudo -u ggc_user bash -c 'python3 -c import pandas"'

which gives me error:

 Module not found.

then I uninstalled the pandas and tried to install it system-wide using

 pip3 install --system pandas

but then i got error:

    Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 360, in run
    prefix=options.prefix_path,
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/pytz'

So my question is, how to make my python modules available to system user ggc_user ? What is the right way to install modules?

martineau
  • 119,623
  • 25
  • 170
  • 301
Anudocs
  • 686
  • 1
  • 13
  • 54
  • 2
    You need to be root to install to `/usr/local/`. Try `sudo pip3 install` – Håken Lid Feb 17 '21 at 19:26
  • Isn't this basically the same question [I answered in a comment 4 hours ago?](https://stackoverflow.com/questions/66243583/making-python-module-work-for-different-users-in-ubuntu-18-04#comment117116296_66243583) The answer you got there does suggest `sudo` with `pip3 install --system` – tripleee Feb 17 '21 at 19:31
  • @HåkenLid what about this https://askubuntu.com/a/802594 ? – Anudocs Feb 17 '21 at 20:03
  • That's a theoretical risk, sure. But you could just check the `setup.py` for pandas before doing it. I would be very surprised if there's malicious code there, since pandas is such a widely used library. https://github.com/pandas-dev/pandas/blob/master/setup.py – Håken Lid Feb 17 '21 at 20:17
  • You could also chmod `/usr/local/lib/python3.6/dist-packages/` so non-root user can write there. Then you don't need sudo to install. But if there actually is an exploit hidden in pandas, it might cause trouble without root also. – Håken Lid Feb 17 '21 at 20:33
  • Just a note that you may wish to upgrade to Py 3.8+ as 3.6 will be out of support Dec ‘21. – S3DEV Feb 17 '21 at 20:47

0 Answers0