Sasha Ahrestani
Sasha Ahrestani

Reputation: 87

Python 3 installed, error when running

I installed Python 3.5.1 on my Mac, alongside Python 2.7.10. When I run python --version, it returns Python 2.7.10, and when I run python3 --version, it returns Python 3.5.1, which should confirm that Python 3 correctly installed. However, whenever I try to run a command or file with python3 in Terminal, it gives me this error:

Fatal Python error: Py_Initialize: unable to load the file system codec File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py", line 123 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax

Current thread 0x00007fff72bb4000 (most recent call first): Abort trap: 6 Farshids-MacBook-Pro-2:mysite Sasha$ python3 Fatal Python error: Py_Initialize: unable to load the file system codec File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py", line 123 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax

Current thread 0x00007fff72bb4000 (most recent call first): Abort trap: 6

and also pops up with a message saying "Python quit unexpectedly." As you can see in the error, it mentions 2.7, which means that it was probably trying to run the code using 2.7.

How do I fix this? By the way, I installed Python 3 to follow a Django tutorial that does not work without Python 3, and I'm so knowledgeable about Python to be able to adjust.

Upvotes: 2

Views: 5363

Answers (2)

Vishal Yarabandi
Vishal Yarabandi

Reputation: 457

You can keep the shebang line (starting with #! on the first line) as python3 (#!/usr/bin/python3.5) path if you are executing them as executables. But the errors you are getting are due to syntax incompatibility between your scripts and the python interpreter you are using. Study the changes in python3.x version and make changes in your scripts accordingly. You can have a look at this for your reference.

Upvotes: 1

Vibhu
Vibhu

Reputation: 167

Most probably $PYTHONPATH is set to use your Python2.x. To verify this type

echo $PYTHONPATH

If you see path related to Python2.x, try unsetting it.

unset PYTHONPATH

Upvotes: 2

Related Questions