PYTHONPATH issues

1,825 views
Skip to first unread message

Stephen Bell

unread,
Jul 18, 2014, 10:22:20 PM7/18/14
to obey-the-test...@googlegroups.com
Hi there. I love the book so far.

I'm having a small problem with Python 2 and Python 3 playing nicely on my MacBook. Here's the error message when I try to do anything with Python 3 (this is from Chapter 2) :

canadabook2-2:superlists stephen.bell$ python3 functional_tests.py

Failed to import the site module

Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!

     PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages:"

     You should `unset PYTHONPATH` to fix this.

canadabook2-2:superlists stephen.bell$ 


I can run "unset PYTHONPATH" as suggested, but I have to run it each time I restart terminal or open a new terminal window/tab. Is there an easy way to fix this more permanently (on a mac)?
pythonpath.png

Harry Percival

unread,
Jul 20, 2014, 6:37:34 AM7/20/14
to Stephen Bell, obey-the-test...@googlegroups.com
Did you ever find a fix for this Steve?  I would try uninstalling + reinstalling python 3...


--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-go...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------------
Harry J.W. Percival
------------------------------
Twitter: @hjwp
Mobile:  +44 (0) 78877 02511
Skype:         harry.percival

Stephen Bell

unread,
Jul 20, 2014, 11:46:43 PM7/20/14
to obey-the-test...@googlegroups.com, stephe...@gmail.com, hj...@cantab.net
Thanks Harry.

Well, it looks like I had a bunch of other junk in my ~/.bash_profile from earlier experiments with Postgres, Ruby on Rails, MacPorts, etc. that was causing the issue. This is the line that was probably causing my trouble:

export PYTHONPATH="/usr/local/lib/python2.7/site-packages:$PYTHONPATH"

I tried running the Python 3.4 installer again, and it's just appending this to the bottom of my .bash-profile each time it's run:
 
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH

After checking my wife's computer, I figured out that a bash_profile isn't set up in OS X by default (and therefore probably wouldn't cause any damage to major systems if removed), so I just erased everything in that file except for the code above (and the 2.7 installer's equivalent). Now when I open up terminal, I can get to "python" and "python3" without any trouble.

I may have trouble later on with some of those other products (MacPorts, RVM, Postgres, etc.), but for now this works, so I'll deal with those later.

If anyone else is reading this and using OS X, you can edit your .bash-profile like this from terminal:

open ~/.bash_profile




On Sunday, July 20, 2014 5:37:34 AM UTC-5, Harry Percival wrote:
Did you ever find a fix for this Steve?  I would try uninstalling + reinstalling python 3...
On 19 July 2014 03:22, Stephen Bell <stephe...@gmail.com> wrote:
Hi there. I love the book so far.

I'm having a small problem with Python 2 and Python 3 playing nicely on my MacBook. Here's the error message when I try to do anything with Python 3 (this is from Chapter 2) :

canadabook2-2:superlists stephen.bell$ python3 functional_tests.py

Failed to import the site module

Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!

     PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages:"

     You should `unset PYTHONPATH` to fix this.

canadabook2-2:superlists stephen.bell$ 


I can run "unset PYTHONPATH" as suggested, but I have to run it each time I restart terminal or open a new terminal window/tab. Is there an easy way to fix this more permanently (on a mac)?

--
You received this message because you are subscribed to the Google Groups "Obey the testing goat! Test-Driven Web Development with Python book" group.
To unsubscribe from this group and stop receiving emails from it, send an email to obey-the-testing-goat-book+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Claudia Rodriguez

unread,
Oct 5, 2016, 1:05:18 PM10/5/16
to Obey the testing goat! Test-Driven Web Development with Python book, stephe...@gmail.com
Thank for the detailed response. It was useful for learning
Thanks Harry.

Reply all
Reply to author
Forward
0 new messages