Ask Your Question
0

F24 - python: how to install package via pip

asked 2016-08-02 08:23:06 -0500

piod gravatar image

I would like to install gspread package in Fedora 24, which should be used by normal user. Despite pip lists gspread I can't import it. How to solve it?

As normal user:

$pip install gspread
[...]
IOError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/gspread-0.4.1.dist-info/METADATA'

$pip install --user gspread
[...]
IOError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/gspread-0.4.1.dist-info/METADATA'

$pip -V
pip 8.0.2 from /usr/lib/python2.7/site-packages (python 2.7)

$python -m gspread
/usr/bin/python: No module named gspread

$pip list
[...]
ecdsa (0.13)
gspread (0.4.1)
iniparse (0.4)
[...]

$sudo pip install --user gspread
Requirement already satisfied (use --upgrade to upgrade): gspread in /usr/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): requests>=2.2.1 in /usr/lib/python2.7/site-packages (from gspread)

As root:

$pip install gspread
Requirement already satisfied (use --upgrade to upgrade): gspread in /usr/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): requests>=2.2.1 in /usr/lib/python2.7/site-packages (from gspread)

I use pip from DNF (python-pip-8.0.2-1.fc24.noarch).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-08-02 10:28:46 -0500

updated 2016-08-02 10:29:21 -0500

The problem you're running into is that Fedora uses Python for much of the common, shared code on which the Operating System relies. As a result, that code is handled by dnf-managed RPM packages. You should definitely avoid installing any Python packages using pip as root, as this could lead to inconsistencies in the dnf-managed, RPM-provided code base.

The best practice for Python on Fedora is to distinguish your Python development packages from the dnf-managed system packages from the get-go by creating a Python virtual environment and ensuring all of your pip-installed packages are placed there. That way, you can install your development tools in an isolated location and you won't do any harm to the Fedora OS should you modify them in a way unexpected by the very many applications depending on that common Fedora codebase.

So, grab the virtualenv tool (sudo dnf install python-virtualenv) and follow the Python virtualenv documentation regarding its use. Basically, you create the virtual environment, source into it, and then use pip and do whatever else you'd like to do safely from within your virtual environment.

That's the best way to keep your Python doings separate from the crucial OS software which you do not want to modify (which you would if you succeeded with your pip command executed as root; don't do that).

edit flag offensive delete link more

Comments

Do I understand correctly - only way of using python in Fedora nowadays is via virtenv?

piod gravatar imagepiod ( 2016-08-02 10:49:34 -0500 )edit

No. You can use all the python utilities installed by the RPM packages without any need to create a virtual environment. If, on the other hand, you want to install packages separately from the OS-provided packages using pip, you should create a virtual environment so that you can install those packages there and isolate your activity from the OS-wide packages, so as not to corrupt anything unintentionally and cause problems with the OS. Make sense?

bitwiseoperator gravatar imagebitwiseoperator ( 2016-08-02 11:30:07 -0500 )edit

One more questions - if I like to install gspread for all users bypassing virtualenv (just like in the question's description) how this should be done?

piod gravatar imagepiod ( 2016-08-05 05:04:46 -0500 )edit

So, I'd use a location in /usr/local/lib/python2.7 (or whatever version you're using) to store Python packages intended for global use which I manage with pip. That way, it's safely segregated from the OS Python files ( stored in /usr/lib/python(2.7|3.[45]) ). You may have to inform the users of the location you choose, but /usr/local is probably the appropriate place to store them, per the Filesystem Hierarchy Standard.

So use a command like sudo pip install -t /usr/local/lib/python2.7 gstream to do it.

bitwiseoperator gravatar imagebitwiseoperator ( 2016-08-08 13:23:53 -0500 )edit

I just want to add that, using a virtual environment as your default python environment (which I find quite useful), you should make the fedora-specific packages available via e.g. python3 -m venv --system-site-packages myenv. Otherwise I ran into some annoying exceptions while using the dnf autocompletion.

greenapple gravatar imagegreenapple ( 2017-01-14 06:30:29 -0500 )edit

Question Tools

Stats

Asked: 2016-08-02 08:23:06 -0500

Seen: 1,097 times

Last updated: Aug 02 '16