Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error when opening python in terminal

I accidentally deleted python folders I had on my machine - which is a macbook, running yosemite, version 10.10.2 (14C1510). I took them out of the trash, but when I try running python, I get this:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

I have read through forums and exported PYTHONHOME to usr/local using this:

export PYTHONHOME=usr/local

When I try running python now, I only get the last error:

ImportError: No module named site

I located the python2.7 folders - there were four of them and moved them to /usr/local/lib. Then I typed in:

export PYTHONHOME = /usr/local/lib/python2.7

It gave me the error:

-bash: export: =': not a valid identifier -bash: export:/usr/local/lib/python2.7': not a valid identifier

HELP!

thanks

like image 213
Hunter Maxfield Avatar asked Apr 08 '15 18:04

Hunter Maxfield


1 Answers

PYTHONHOME should point to the directory of the standard python library. There are a couple of problems with what you are doing at the moment.

  1. usr/local is a relative path. You should use an absolute path, i.e. /usr/local
  2. /usr/local is likely not a suitable location for your python libraries, it is likely to be something like /usr/local/lib/python2.7 or /usr/local/lib/python3.5

In terminal try using this command:

ls /usr/local/lib

Now look through the results for the correct python install that you wish to use. Now set your PYTHONHOME variable using

export PYTHONHOME=/usr/local/lib/pythonXXX

replacing the XXX to complete the desired path. Notice how the path contains a leading forward slash to make it an absolute path!

like image 175
Matt Davidson Avatar answered Oct 01 '22 11:10

Matt Davidson