5

I have a question regarding the order of imports and paths placed by default in sys.path by Python 2 and Python 3. I compared the default paths in my sys.path in both Python 2.7 and 3.4 with PYTHONPATH set to empty. I'm on Ubuntu 14.10.

I also have numpy installed both system-wide through apt-get in /usr/lib (version 1.8.2) and locally in /home/user/.local/lib (version 1.9.2) for both Python 2 and Python 3.

I get the following results:

Python 2.7

>>> print('\n'.join(sys.path))
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-dynload
/home/user/.local/lib/python2.7/site-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/pymodules/python2.7
>>> import numpy
>>> numpy.version 
<module 'numpy.version' from /home/user/.local/lib/python2.7/site-packages/numpy/version.pyc'>
>>> numpy.version.version
'1.9.2'

Python 3.4

>>> print('\n'.join(sys.path))
/usr/lib/python3/dist-packages
/usr/lib/python3.4
/usr/lib/python3.4/plat-x86_64-linux-gnu
/usr/lib/python3.4/lib-dynload
/home/user/.local/lib/python3.4/site-packages
/usr/local/lib/python3.4/dist-packages
>>> import numpy
>>> numpy.version 
<module 'numpy.version' from '/usr/lib/python3/dist-packages/numpy/version.py'>
>>> numpy.version.version
'1.8.2'

Could you help me understand why in Python 3 /usr/lib/python3/dist-packages is higher than /home/user/.local/lib/python3.4/site-packages which results in my older system installation of numpy being imported by default, while it's the other way around in Python 2?

asked May 30, 2015 at 1:22

1 Answer 1

1

I'm pretty sure this is an ubuntu thing, not a Python thing. Check the global site customize (in /etc/python2.7 and /etc/python3.4) as well as the site.py files in /usr/lib/python2.7 and /usr/lib/python3.4.

answered Jun 2, 2015 at 4:05
Sign up to request clarification or add additional context in comments.

2 Comments

There indeed are differences between the site.py files in /usr/lib/pythonX.X (no differences in /etc/pythonX.X). However, I cannot see anything obvious that would explain the difference I describe. I wasn't really aware of the existence of those files, though, and it's useful to know about them.
@AndrzejPronobis, I faced the same issue, how I can fix it, please?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.