Python是新的流行语言,特别是在金融行业,我开始学习它。我从Python网站上下载了它——Python版本3.5.2——并且安装成功了……在我的应用程序文件夹。我想让你对我有更多的了解,我在法国的IT工程学校上学,所以我有IT文化,但是我从来没有黑客的灵魂,所以有些事情可能比其他事情更难。
开始在Python IDE上编写代码,然后我创建了一个可执行的Python文件,当我试图执行它时…错误! !
这是我执行我的文件时得到的结果(bissextile.py - file应该要求用户输入年份并告诉他这一年是否是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
{rtf1ansiansicpg1252cocoartf1404cocoasubrtf470
^
SyntaxError: unexpected character after line continuation character
# A lot of cleaning up files after that...
所以,我在这里看到了两个问题:我的文件坏了……2)外壳不是使用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$ which python/usr/bin/python和:
**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.**
我不能把所有的链接,我已经研究到目前为止(特别是堆栈溢出的文章;)),因为我没有足够的"声誉",但我做了很多研究,没有文章似乎回应我的问题。我不知道怎么了。
使用python3 my_script.py
或添加shebang #!/urs/bin/python3
从命令行运行程序