Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Python still uses local python sys.path #13260

Closed
eduardocereto opened this issue Jul 7, 2012 · 7 comments
Closed

Python still uses local python sys.path #13260

eduardocereto opened this issue Jul 7, 2012 · 7 comments
Labels

Comments

@eduardocereto
Copy link

For me it only happens for Python2, maybe because I don't have python3 on my machine other than the version from Homebrew.

It's a bad idea to inherit the paths from the system because when you try to install an updated package pip will try to remove the previous package from the system and it fails unless you use sudo.

When running python you can see that sys.path contains/Library/Python/2.7/site-packages. It should only contain paths to the cellar site-packages.

bash-3.2$ which pip
/usr/local/share/python/pip
bash-3.2$ which python
/usr/local/bin/python
bash-3.2$ python
Python 2.7.3 (default, Jul  7 2012, 01:32:44) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.27-py2.7.egg', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/Library/Python/2.7/site-packages/pip-1.0.2-py2.7.egg', '/Library/Python/2.7/site-packages/closure_linter-2.3.1-py2.7.egg', '/Library/Python/2.7/site-packages/pyboleto-0.2.3-py2.7.egg', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages', '/Library/Python/2.7/site-packages/PIL']
>>> 
bash-3.2$ which pip-3.2
/usr/local/share/python3/pip-3.2
bash-3.2$ which python3
/usr/local/bin/python3
bash-3.2$ python3
Python 3.2.3 (default, Jul  7 2012, 01:38:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/distribute-0.6.27-py3.2.egg', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/pip-1.1-py3.2.egg', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python32.zip', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python3.2', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python3.2/plat-darwin', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python3.2/lib-dynload', '/usr/local/Cellar/python3/3.2.3/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages']
>>> 
bash-3.2$ exit
exit

Script done on Sat Jul  7 02:05:17 2012
@samueljohn
Copy link
Contributor

You are right and I have a pull request for the python formula that fixes this among some other things. I am on the iPhone right now, so I can't give you the link. Look through the open pull requests for my username. Feel free to try my attempt.

@eduardocereto
Copy link
Author

That's right it's #12968 so I'll just close this issue. It seems to address the problem addid the -L compiler flag workaround. Related to this python bug:

http://bugs.python.org/issue11445

UPDATE

Tried @samueljohn branch but it doesn't solve the issue.

@eduardocereto
Copy link
Author

I'm reopening this issue because #12968 acctually doesn;t solve it.

@samueljohn
Copy link
Contributor

Well, actually that is a feature not a bug, @eduardocereto. See the discussion on the python list. At least it is intended by Python. Though, one core dev was "+0" about it as I read from the mailing list.

Framework builds of python include /Library/Python/2.7/site-packages but don't install there. This is also true for the python downloaded from python.org. Homebrew's Python doesn't move any files to that directory. It's just a place where you can put python modules but you don't have to. Probably with Lion, Apple made this directory writable only by admin.

But still, I see your issue that pip wants to remove old packages installed there and fails without sudo.
Not sure what to do. Some people may want to put modules there shared between different python2.7 installations. I don't want to disable that. I wasn't able to make pip ignore the stuff in that dir and I tried with different options.

What bothers me more is that there is no directory searched only by systems python and not by homebrew-python except the stuff in /System where the user really should not install to. So right now it's not possible to install only for system python.

@eduardocereto
Copy link
Author

That's really unfortunate. This bug clearly don't belong here then. I'll have to suck it. I'll most probably just pop the dirs I don't want from sys.path.

I thought it was a bug on the packaging since for me it's something I would never expect.

@samueljohn thanks again for digging into this

@samueljohn
Copy link
Contributor

@eduardocereto, thanks for reporting! Sorry that I don't have a good solution at hand. I mean, if we come to the conclusion, it's better to build python in homebrew without /Library/Python/2.7/site-packages in the sys.path and if that is possible (don't know right now) we can change that. But I bet then people will report exactly that as a new issue/bug :-/

@samueljohn
Copy link
Contributor

Just for the record (and if you come here by a search engine):

A brewed Python uses what it finds in /Library/Python/2.7/site-packages (so you can put your global stuff there). This is a feature of Python. We don't disable this.

But brewed Python now avoids any things pointing to /System....
For your personal stuff I recommend installing pip install --user something, so you don't need sudo.

@Homebrew Homebrew locked and limited conversation to collaborators Feb 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants