2

Iam working on a server without root access and after a restart it seems my Path variables for are destroyed. As Iam not permitted to use virtualenv, I use pip install --user package to install python packages.

Since a restart, I can only use outdated libraries in /usr/lib/python2.7/dist-packages, but not /.local/lib/python2.7/site-packages.

I can also not use packages like scrapy or spyder from the .local path in the terminal. I already set export PYTHONPATH=$PYTHONPATH:/.local/lib/python2.7/site-packages, but there are no changes.

The .local path is also not shown if I run print(sys.path) in python.

Do I have to change some other path?

The OS is Ubuntu 14.04.

Thank you in advance.

Norovis
  • 21
  • 3
  • I have the same problem. But for me, IPython still gets the right `sys.path` and imports the modules installed in `.local/lib/python2.7/site-packages`. This problem is mentionned [here](https://stackoverflow.com/questions/23209192/ipython-sys-path-different-from-python-sys-path) but it still doesn't explain why suddenly python decided to use the wrong site-packages... – PlasmaBinturong Jun 01 '16 at 17:08

1 Answers1

0

Please try the following:

whereis python

Python always uses the first package it finds. The PYTHONPATH gets appended to sys.path, after the system one. So it will normally find the system one first. But the "official" per-user packages directory seems to be placed before that. So create your personal site-packages directory:

mkdir -p $HOME/.local/lib64/python2.7/site-packages
mkdir $HOME/bin

(You may have to change "lib64" to "lib32" or just "lib")

This directory gets placed before the system one on my system. But you should verify it by printing out sys.path.

Then install your packages into there. However, the --user option in the latest pip version should already place it there.

As a list resort you can manipulate sys.path. You can insert your directory into sys.path before the system site-packages.

You can pass additional options to install scripts in your $HOME/bin directory.

Install like this:

pip install --user --install-option="--install-scripts=$HOME/bin"
Chhabilal
  • 1,076
  • 11
  • 22
  • 2
    Thank you for the fast response. This shows the Python path, but the .local path is not there. I would like to know, how to add the pip user path to the python path (I already tried to modify $PYTHONPATH) – Norovis May 12 '16 at 14:02