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.

1
  • 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 but it still doesn't explain why suddenly python decided to use the wrong site-packages... Commented Jun 1, 2016 at 17:08

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

1 Comment

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.