首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Mac OS X 10.11.6上正确升级到Python -/etc/path文件问题

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

Stack Overflow用户
提问于 2016-08-11 00:55:28
回答 1查看 290关注 0票数 1

Python是新的流行语言,特别是在金融行业,我开始学习它。我从Python网站下载了它- Python版本3.5.2 -它成功地安装了...在我的应用程序文件夹中。为了让你更多地了解我自己,我在法国上过一所IT工程学校,所以我有IT文化,但我从来没有黑客的灵魂,所以有些事情可能比其他事情更困难。

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

这是我执行文件时得到的结果(bissextile.py - file应该要求用户输入年份,并告诉他今年是否为双六位数):

代码语言:javascript
运行
复制
    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 ...and将要从我的mac中删除一些系统文件:)它不让我do...decided我真的不知道我在做什么,我应该在互联网上多挖掘一点。根据记录,下面是我在/System/Library/Frameworks/python.framework/Versions/中拥有的内容:

所以我找到了一个叫做" Homebrew“的东西,它应该为你安装Python,我遵循了这个很棒的教程:http://blog.manbolo.com/2014/09/27/use-python-effectively-on-os-x#p1要求Homebrew安装Python3.5而不是Python2.7(步骤完全相同),我显然是这么做的。

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

代码语言:javascript
运行
复制
    /usr/local/bin
    /usr/bin
    /bin
    /usr/bin
    /bin

/usr/local/bin是文件中的第一个二进制文件,我检查了它包含Python3.5的文件夹。但是不管文件的第一行是什么: MacBook-Pro-de-Tebah:~ tebahsaboun /usr/bin/python和:

代码语言:javascript
运行
复制
    **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.**

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

EN

回答 1

Stack Overflow用户

发布于 2016-08-11 05:12:22

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38879385

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档