This repository has been archived by the owner. It is now read-only.

fix for python3 error when running python's 2 sitecustomize #16848

wants to merge 1 commit into


None yet
6 participants

fabiomcosta commented Jan 2, 2013

When running python3 installed with brew, while also having brew's current python formula, I get an error:

Error in sitecustomize; set PYTHONVERBOSE for traceback:
ValueError: list.remove(x): x not in list


  File "/usr/local/lib/python2.7/site-packages/", line 21, in <module>
ValueError: list.remove(x): x not in list

Since python3 doesn't have that path inside it's sys.path, the ValueError happens.

Python3 also imports this sitecustomize module and throws a ValueErro…
…r since "#{site_packages_cellar}" is not inside sys.path

samueljohn commented Jan 3, 2013

But wait. Something different is wrong. You probably have set the PYTHONPATH to the python 2.x site-packages dir and then start python3. Try removing the PYTHONPATH altogether since all brewed Pythons have their respective site-packages built-in. Setting PYTHONPATH is only needed if you want to run system's Python and be able to import the modules installed by Homebrew.

But thanks anyway for this report, I will try to guard that sys.path.remove command better.


fabiomcosta commented Jan 3, 2013

@samueljohn you're a beast! :)
I didn't realise that I was adding the python 2.7 path to my PYTHONPATH. Cleaning my PYTHONPATH solved the problem.
Thank you for your help!

Anyways do you think we should add the try catch or should we close the issue?


samueljohn commented Jan 3, 2013

Sadly, there is no PYTHONPATH3, so all Pythons use the PYTHONPATH. Therefore, one has to be careful.

But you are right about the fact that sys.path.remove should be guarded - better than just checking the prefix of the Python interpreter.

But I think that if PYTHONPATH is set and a brewed python3 is started, we should also not add the site-package dir. Perhaps it's best to check if sys.version_info.major == 2 or something?


fabiomcosta commented Mar 15, 2013

@hyh1048576 you can unset it (ie: unset PYTHONPATH) or simply not set it in the first place.


samueljohn commented Mar 15, 2013

Right now, I can only suggest to unset or change the PYTHONPATH to only include the one or the other, as @fabiomcosta said.

I am currently working on awesome python 2.x and 3.x support in homebrew and the will look like this:

So, there will be a guard. You can, if you like, add such a guard to your current (located in /usr/local/lib/pythonX.Y/site-packages/, so you can have both site-packages in the PYTHONPATH.


samueljohn commented Mar 15, 2013

@fabiomcosta are you okay with my proposed instead of your proposed fix in this pull request?


fabiomcosta commented Mar 15, 2013

@samueljohn I'm sure you know better than me what is best! Go for it :)

On Friday, March 15, 2013, Samuel John wrote:

@fabiomcosta are you okay with my
proposed instead of your proposed fix in this pull

Reply to this email directly or view it on GitHub

Fábio Miranda Costa
twitter: @fabioMiranda
github: fabiomcosta

@ghost ghost assigned samueljohn Mar 15, 2013


samueljohn commented Jun 8, 2013

Our is now only doing stuff for the python version installed for. Thanks for reporting!!

@samueljohn samueljohn closed this Jun 8, 2013

@n8henrie n8henrie referenced this pull request in textmate/python.tmbundle Aug 27, 2013


Avoid Python3 "list.remove(x): x not in list" error #27

diegomvh pushed a commit to prymatex/python.tmbundle that referenced this pull request Nov 5, 2013

Avoid Python3 "list.remove(x): x not in list" error
Every time TextMate2 updates (and refreshes this file), I get the following error running in-app with Python3 (Python works fine).

	Error in sitecustomize; set PYTHONVERBOSE for traceback: ValueError: list.remove(x): x not in list

It looks like my sitecustomize is being run twice with Python3 (lines 20-25), which is provoking the error; the `os.environ['TM_BUNDLE_SUPPORT']` is removed the first time, so it gives an error trying to remove it the second.

This problem has also been looked at [here](Homebrew/legacy-homebrew#16848) and [here](

sc68cal commented Jan 12, 2014

I am currently experiencing this error - I have mutt installed and it invokes a Python script as a display_filter , and it displays this error. Only by commenting out the following line in Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/ is the issue fixed.

    # Fix 2)
    #   Remove brewed Python's hard-coded site-packages


mistydemeo commented Jan 12, 2014

@sc68cal That code isn't in the sitecustomize any more, so it shouldn't come up on newer python installs.

sc68cal commented Jan 13, 2014

@mistydemeo - can you share some details? I'm running brew version 0.9.5 and 133ec4b


mistydemeo commented Jan 13, 2014

I tracked the comment from the code you had to the that was formerly written by Homebrew during the python3 install. Due to changes in the Python code that particular section is no longer written, and a bugfix went in to the line you highlighted - likely to solve the issue you're having. If you completely remove python3 and then brew install from scratch, you might be okay.

(I think python32 from homebrew/versions still has the issue, so that might need attention...)

sc68cal commented Jan 13, 2014

This was a fresh install, so I don't think it has been fixed.

colons commented Jan 19, 2014

Getting what seems to be the same thing from an install a few days old. Commenting out that line in prevents the error, and there does not appear to be any other ill effects.

pfw commented Jan 20, 2014

I get the same error and the file:
has a 3.3.2 in the sys.path.remove line. Changing 3.3.2 to 3.3.3 fixes the error.

@xu-cheng xu-cheng 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.