在Mac OS X 10.11.6上正确升级到Python - / etc / paths文件问题

时间:2016-08-10 16:55:28

标签: python shell python-3.x osx-elcapitan

Python是新的时尚语言,特别是在金融行业,我开始学习它。 我从Python网站下载它 - Python版本3.5.2 - 它已成功安装在我的Application文件夹中。 为了让你对自己有更多的了解,我在法国建立了一所IT工程学院,所以我有一种IT文化,但我从未有过黑客的灵魂所以有些东西可能比其他东西更难。

开始在Python IDE上编码,然后我创建了一个可执行的python文件,当我尝试执行它时...错误!!

这是我执行文件时得到的结果(bissextile.py - 文件应该要求用户输入一年并告诉他今年是否是bissextile):

    Last login: Tue Aug  9 23:24:02 on ttys000
    MacBook-Pro-de-Tebah:~ tebahsaboun$ cd '/Users/tebahsaboun/Desktop/' && '/usr/bin/pythonw' -d -v  '/Users/tebahsaboun/Desktop/bissextile.py'  && echo Exit status: $? && exit 1
    # installing zipimport hook
    import zipimport # builtin
    # installed zipimport hook
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py
    import site # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.pyc
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py
    import os # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc
    import errno # builtin
    import posix # builtin
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py
    import posixpath # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.pyc
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stat.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stat.py
    import stat # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stat.pyc
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py
    import genericpath # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.pyc
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/warnings.pyc matches 
    [...] A LOT OF STUFF THAT'S THE SAME AS BEFORE
    import encodings.aliases # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/aliases.pyc
    # /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.pyc matches /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py
    import encodings.utf_8 # precompiled from /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.pyc
    Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
    [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    File "/Users/tebahsaboun/Desktop/bissextile.py", line 1
        {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf470
                                                          ^
    SyntaxError: unexpected character after line continuation character
    # A lot of cleaning up files after that...

所以,我在这里看到两个问题: 1)我的文件不起作用...... 2)shell不使用Python 3.5,而是Python 2.7,这是我需要帮助的问题。

关于互联网的大量研究,我即将遵循该教程: https://wolfpaulus.com/journal/mac/installing_python_osx/comment-page-3/#comment-101285 ...并且即将从我的mac删除一些系统文件:)它不允许我这样做...决定我不知道我在做什么,我应该在互联网上多挖一点。 为了记录,这是我在/System/Library/Frameworks/python.framework/Versions/中的内容:

所以我找到了一个名为“Homebrew”的东西,假设你要安装Python,我遵循了这个很棒的教程: http://blog.manbolo.com/2014/09/27/use-python-effectively-on-os-x#p1 要求Homebrew安装Python 3.5而不是Python 2.7(步骤完全相同),我显然是这样做的。

所以我做了教程中建议的验证,以确保我使用的是正确版本的Python,但是当我问shell时,我仍然使用Python 2.7。 我检查了我的/ etc / paths文件,如下所示:

    /usr/local/bin
    /usr/bin
    /bin
    /usr/bin
    /bin

/ usr / local / bin是文件中的第一个二进制文件,我确实检查了它包含Python 3.5的文件夹。但无论我得到的文件中的第一行是什么:         MacBook-Pro-de-Tebah:~tebahsaboun $哪个是python         在/ usr / bin中/蟒蛇 并且:

    **MacBook-Pro-de-Tebah:~ tebahsaboun$ python
    Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
    [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.**

我不能把到目前为止我研究过的所有链接(特别是堆栈溢出文章);)因为我没有足够的“声誉”,但我做了很多研究,似乎没有文章回应我的问题。我不明白出了什么问题。

1 个答案:

答案 0 :(得分:0)

使用python3 my_script.py从命令行运行程序或添加shebang #!/urs/bin/python3