Skip to content


Subversion checkout URL

You can clone with
Download ZIP


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

wants to merge 1 commit into from

7 participants


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.

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

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.


@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?


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 I have a similar problem. Can you give me a hint on how to clean that?

Either python or python3 will complain, depending on which one I put first in $PYTHONPATH.

Shall I just make it empty?


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


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.


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

@samueljohn samueljohn was assigned

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

@samueljohn samueljohn closed this
@n8henrie n8henrie referenced this pull request in textmate/python.tmbundle

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

@diegomvh diegomvh referenced this pull request from a commit in prymatex/python.tmbundle
@n8henrie n8henrie 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/homebrew#16848) and [here](

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


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


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


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...)


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


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.


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2013
  1. @fabiomcosta

    Python3 also imports this sitecustomize module and throws a ValueErro…

    fabiomcosta authored
    …r since "#{site_packages_cellar}" is not inside sys.path
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +6 −2 Library/Formula/python.rb
8 Library/Formula/python.rb
@@ -150,8 +150,12 @@ def install
sys.path = [ p for p in sys.path if not p.startswith('/System') ]
# Fix 2)
- # Remove brewed Python's hard-coded site-packages
- sys.path.remove('#{site_packages_cellar}')
+ # Remove brewed Python's hard-coded site-packages,
+ # if it's there
+ try:
+ sys.path.remove('#{site_packages_cellar}')
+ except ValueError:
+ pass
# Fix 3)
# For all Pythons: Tell about homebrew's site-packages location.
Something went wrong with that request. Please try again.